菜鸟教程小白 发表于 2022-12-11 19:10:50

ios - ScrollView 进入内容页面推送异步不起作用


                                            <p><p>我需要你的帮助。我实际上是从 Xamarin.forms 开始的。
我有一个 HomePage:TabbedPage,它有 3 个 ContentPage。 </p>

<p>这 3 个页面中的一个是 ListView,在点击项目时,它会调用另一个带有 ScrollView 的内容页面。</p>

<pre><code>ListView.ItemTapped += async (o, e) =&gt;
{
    var myList = (ListView)o;
    var newPage = (myList.SelectedItem as Object);
    await Navigation.PushAsync(new Page(Object));
    myList.SelectedItem = null; // de-select the row
};
</code></pre>

<p>我在这个新页面上有一个 ScrollView,但它不起作用。 </p>

<p>我复制了页面并在没有 Navigation.PushAsync 的情况下调用它,并且滚动工作。</p>

<p>我实际上只使用 iOS 模拟器。</p>

<p>你知道原因吗? </p>

<p>我正在使用 xaml。</p>

<p>非常感谢。如果您需要更多信息,请告诉我..! </p>

<p>还有我的 App.xaml.cs</p>

<pre><code>public App()
    {
      InitializeComponent();

      MainPage = new HomePage();
    }
</code></pre>

<p>这是我的主页:</p>

<pre><code>public class HomePage : TabbedPage
{
    public HomePage()
    {
      var profilPage = new NavigationPage(new UserPage());
      profilPage.Title = &#34;Profil&#34;;
      profilPage.Icon = &#34;user.png&#34;;
      var gameListPage = new NavigationPage(new GameListPage());
      gameListPage.Title = &#34;Jeux&#34;;
      gameListPage.Icon = &#34;gamepad.png&#34;;
      Children.Add(profilPage);
      Children.Add(gameListPage);
   }
}
</code></pre>

<p>我的主页调用 GameListPage :</p>

<pre><code>&lt;ContentPage.Content&gt;
    &lt;ListView x:Name=&#34;GameListView&#34;&gt;
      &lt;ListView.ItemTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;TextCell Text=&#34;{Binding name}&#34; /&gt;

          &lt;/DataTemplate&gt;
      &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
&lt;/ContentPage.Content&gt;
</code></pre>

<p>有事件:</p>

<pre><code>GameListView.ItemTapped += async (o, e) =&gt;
      {
            var myList = (ListView)o;
            var game = (myList.SelectedItem as Game);
            await Navigation.PushAsync(new GamePage(game));
            //await DisplayAlert(&#34;Tapped&#34;, game.name, &#34;OK&#34;);
            myList.SelectedItem = null; // de-select the row
      };
</code></pre>

<p>GamePage 在这里:</p>

<p>gamePage.xaml</p>

<pre><code>    &lt;ContentPage.Content&gt;
    &lt;ScrollView&gt;
      &lt;RelativeLayout x:Name=&#34;RelativeLayout&#34;HorizontalOptions=&#34;FillAndExpand&#34; VerticalOptions=&#34;FillAndExpand&#34;&gt;
            &lt;Grid RelativeLayout.WidthConstraint =
          &#34;{ConstraintExpression Type=RelativeToParent,
                                 Property=Width,
                                 Factor=1,
                                 Constant=0}&#34;
      RelativeLayout.HeightConstraint =
          &#34;{ConstraintExpression Type=RelativeToParent,
                                 Property=Height,
                                 Factor=1,
                                 Constant=0}&#34;&gt;
            &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height=&#34;500&#34;&gt;
                  &lt;/RowDefinition&gt;
                  &lt;RowDefinition Height=&#34;500&#34;&gt;
                  &lt;/RowDefinition&gt;
                  &lt;RowDefinition Height=&#34;550&#34;&gt;
                  &lt;/RowDefinition&gt;
                  &lt;RowDefinition Height=&#34;20&#34;&gt;
                  &lt;/RowDefinition&gt;
                  &lt;RowDefinition Height=&#34;300&#34;&gt;
                  &lt;/RowDefinition&gt;
                  &lt;RowDefinition Height=&#34;500&#34;&gt;
                  &lt;/RowDefinition&gt;
                &lt;/Grid.RowDefinitions&gt;
                &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width=&#34;*&#34;&gt;
                  &lt;/ColumnDefinition&gt;
                  &lt;ColumnDefinition Width=&#34;*&#34;&gt;
                  &lt;/ColumnDefinition&gt;
                  &lt;ColumnDefinition Width=&#34;*&#34;&gt;
                  &lt;/ColumnDefinition&gt;
                &lt;/Grid.ColumnDefinitions&gt;
                &lt;Grid.Children&gt;

                  &lt;StackLayout Grid.Row=&#34;0&#34; Grid.Column=&#34;0&#34; Grid.ColumnSpan=&#34;3&#34;&gt;
                        &lt;BoxView BackgroundColor=&#34;Black&#34; HeightRequest=&#34;500&#34;&gt;&lt;/BoxView&gt;
                  &lt;/StackLayout&gt;
                  &lt;StackLayout Grid.Row=&#34;1&#34; Grid.Column=&#34;0&#34; Grid.ColumnSpan=&#34;3&#34;&gt;
                        &lt;BoxView BackgroundColor=&#34;Black&#34; HeightRequest=&#34;500&#34;&gt;&lt;/BoxView&gt;
                  &lt;/StackLayout&gt;
                  &lt;StackLayout Grid.Row=&#34;2&#34; Grid.Column=&#34;0&#34; Grid.ColumnSpan=&#34;3&#34;&gt;
                        &lt;BoxView BackgroundColor=&#34;Black&#34; HeightRequest=&#34;500&#34;&gt;&lt;/BoxView&gt;
                  &lt;/StackLayout&gt;
                &lt;/Grid.Children&gt;
         &lt;/Grid&gt;
          &lt;/RelativeLayout&gt;
    &lt;/ScrollView&gt;
&lt;/ContentPage.Content&gt;
</code></pre>

<p></p>

<p>我把这个内容实际上是为了测试滚动。而且,在另一个 contentPage 中,具有相同的内容,我可以滚动。它就在这个页面上,通过 async Navigation.PushAsync 调用...</p>

<p>已编辑:解决了 StackLayout 与 HeightRequest 到 1500。我的滚动工作现在..临时解决了所以.. 它不正确</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我建议您为您的 View 设置一个 <code>BackgroundColor</code>,例如:</p>

<p><code>ScrollView mainContainer = new ScrollView{
背景颜色 = 颜色.红色
};</code></p>

<p>因此,您可以仔细检查您的 View 实际上是否正在渲染到 <code>ContentPage</code> 本身。</p>

<p>另外一个问题可能是 ScrollView 上没有足够的元素(<code>Label、Image、Entry、Button</code>...随便:<a href="https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/views/" rel="noreferrer noopener nofollow">https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/views/</a>)来实际滚动。</p >

<p>为您的 View 设置测试背景颜色,并让我们知道实际问题所在。</p>

<p>还请记住,ScrollView 具有 <code>Content</code> 属性,因此您可以向其添加布局。示例:</p>

<pre><code>var stack = new StackLayout();

for (int i = 0; i &lt; 100; i++)
{
    stack.Children.Add(new Button { Text = &#34;Button &#34; + i });
}

MainPage = new ContentPage
{
    Content = new ScrollView { Content = stack }
};
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios -ScrollView 进入内容页面推送异步不起作用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42674867/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42674867/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - ScrollView 进入内容页面推送异步不起作用