【问题标题】:Xamarin Forms ScrollView issue with Editor when using the software Keyboard使用软件键盘时,Xamarin Forms ScrollView 出现编辑器问题
【发布时间】:2018-12-20 10:48:50
【问题描述】:

我在 iOS 中使用 Xamarin Forms。我在滚动视图中有一个编辑器。编辑器设置为填充大部分页面。这是有效的。

<ContentPage.Content>
    <ScrollView>
    <StackLayout>
        <Editor x:Name="NotesEditor" Text="{Binding Contact.AttendanceDetails.Notes, Mode=TwoWay}"  VerticalOptions="FillAndExpand" 
            HorizontalOptions="FillAndExpand" BackgroundColor="AliceBlue" TextChanged="NotesEditor_TextChanged"  ></Editor>
        <Label x:Name="RemainingText" VerticalOptions="Fill" HorizontalOptions="CenterAndExpand" HeightRequest="40"></Label>
    </StackLayout>
    </ScrollView>
</ContentPage.Content>

问题是当使用软键盘时,页面滚动,当用户开始输入时,如果没有手动滚动,他们最初看不到他们在键盘上输入的文本。

有没有办法软件键盘不推动滚动视图?所以用户可以手动完成吗?

任何想法都将不胜感激。

【问题讨论】:

    标签: xamarin.forms xamarin.ios editor scrollview


    【解决方案1】:

    我不确定您的用例,但为什么不完全删除 ScrollView ?如果编辑器是全屏的,则没有理由滚动,如果您仍然想看到它,可以对标签应用边距。

    <ContentPage.Content>
        <StackLayout>
            <Editor x:Name="NotesEditor" Text="{Binding Contact.AttendanceDetails.Notes, Mode=TwoWay}"  VerticalOptions="FillAndExpand" 
                HorizontalOptions="FillAndExpand" BackgroundColor="AliceBlue" TextChanged="NotesEditor_TextChanged"  ></Editor>
            <Label x:Name="RemainingText" VerticalOptions="Fill" HorizontalOptions="CenterAndExpand" HeightRequest="40" margin="10, 30, 10, 30"></Label>
        </StackLayout>
    </ContentPage.Content>
    

    【讨论】:

    • 好吧,他需要滚动视图,以便编辑器在显示时用键盘滑动而不是消失。
    • 我需要滚动视图,就好像有大量文本甚至超出屏幕等一样,不幸的是,无法控制滚动。我已经解决了,我也会给出答案。感谢您的帮助。
    【解决方案2】:

    试试这个组件,它可能不需要 scrollView 就可以工作。但是,如果您启用了编辑器的扩展,它将失败。

    https://devlinduldulao.pro/how-to-fix-keyboard-overlapping-or-covering-entry/

    【讨论】:

      【解决方案3】:

      通过向 Editor Focused 事件添加事件来管理修复:

      XAML:

      <ScrollView x:Name="scrollview">
          <StackLayout>
              <Editor x:Name="NotesEditor" Text="{Binding Contact.Notes, Mode=TwoWay}"  VerticalOptions="FillAndExpand" 
                  HorizontalOptions="FillAndExpand" BackgroundColor="AliceBlue" TextChanged="NotesEditor_TextChanged" Focused="NotesEditor_Focused"   ></Editor>
              <Label x:Name="RemainingText" VerticalOptions="Fill" HorizontalOptions="CenterAndExpand" HeightRequest="40"></Label>
          </StackLayout>
          </ScrollView>
      

      后面的代码:

      private void NotesEditor_Focused(object sender, FocusEventArgs e)
          {
              scrollview.ScrollToAsync(0, 0,true);
          }
      

      【讨论】:

        【解决方案4】:

        如果你想在滚动视图中使用编辑器,你可以试试这个解决方案。

        <ContentPage>
         <ScrollView >
                          <Grid VerticalOptions="FillAndExpand">
                                      <Grid.RowDefinitions>
                                     <RowDefinition Height="Auto" />
                                       </Grid.RowDefinitions>
                             
                           <Editor VerticalOptions="FillAndExpand"
                                                               AutoSize="TextChanges"
                                      -----
                                      Grid.Row="0" />
                             </Grid>
          </ScrollView>
        </ContentPage>
        

        例如:你的代码应该是这样的

        <ContentPage.Content>
            <ScrollView>
           <Grid VerticalOptions="FillAndExpand">
                                      <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                         <RowDefinition Height="Auto" />
                                       </Grid.RowDefinitions>
                <Editor x:Name="NotesEditor" Text="{Binding Contact.AttendanceDetails.Notes, Mode=TwoWay}"  VerticalOptions="FillAndExpand" 
                    HorizontalOptions="FillAndExpand" BackgroundColor="AliceBlue" TextChanged="NotesEditor_TextChanged" Grid.Row="0" ></Editor>
                <Label x:Name="RemainingText" VerticalOptions="Fill" HorizontalOptions="CenterAndExpand" HeightRequest="40" Grid.Row="1"></Label>
            </Grid>
            </ScrollView>
        </ContentPage.Content>
        

        注意:如果需要,您可以为滚动视图设置 hightRequest。

        【讨论】:

          猜你喜欢
          • 2018-09-15
          • 1970-01-01
          • 2018-12-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-02
          相关资源
          最近更新 更多