如果稍微倾斜 ios 设备,sfcombobox 会以 xamarin 形式向上滚动到顶部

if slightly tilt the ios device, sfcombobox scrolled up to top in xamarin forms

如果稍微倾斜 ios 设备,当我们第一次进入页面时,xamarin.forms.it 中的 sfcombobox 向上滚动到顶部。

<combobox:SfComboBox DataSource="{Binding SamplePickerList, Mode=TwoWay}" HorizontalOptions="FillAndExpand"  SelectedIndex="{Binding SamplePickerIndex, Mode=TwoWay}"
                  VerticalOptions="FillAndExpand" SelectedItem="{Binding SamplePicker,Mode=TwoWay}" />

您可以通过使用SfComboBox Renderer 并获取设备旋转和UITableView 内容偏移位置来解决此问题。您可以通过查看其 ContentOffset 属性.

轻松获取 table 视图的确切偏移量

样本:https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBox_ScrollResetRotating-1020669557

代码片段:

public class CustomComboBoxRenderer : SfComboBoxRenderer
{
        /// <summary>
        /// Find device rotation.
       /// </summary>
       UIDeviceOrientation orientation;
      public CustomComboBoxRenderer()
      {
             Foundation.NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIDeviceOrientationDidChangeNotification"), this.DeviceRotated);
      }
      private async void DeviceRotated(NSNotification obj)
      {
            if (this.Control.Text == string.Empty && this.Control.IsSuggestionOpen)
            {
                //// Get the table view position.
                var offset = this.Control.AutoCompleteTableView.TableView.ContentOffset;
                await System.Threading.Tasks.Task.Delay(1);
                //// Set the table view position while rotating.
                this.Control.AutoCompleteTableView.TableView.ContentOffset = offset;
            }
     }
} 

在此示例中,我们使用 UIDeviceOrientation 保存旋转前的滚动位置,然后在设备倾斜后滚动到该行。