xaml - 如果稍微倾斜 ios 设备,sfcombobox 会在 xamarin 表单中向上滚动
问题描述
如果稍微倾斜 ios 设备,sfcombobox 在 xamarin.forms 中向上滚动到顶部。这是在我们第一次进入页面时发生的。
<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 view 的确切偏移量。
代码片段:
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 保存旋转前的滚动位置,然后在设备倾斜后滚动到该行。
推荐阅读
- python - 将过滤器字典匹配到另一个 - Python
- angular - 错误类型错误:“_co.bankId 未定义”(Angular 7)
- java - 带有 Kafka 源和 Dataflow 运行器的 Beam java SDK 2.10.0:窗口化的 Count.perElement 永远不会触发数据
- python - 如何通过聚合循环运行数据框列表?
- java - 使用模拟服务进行 H2 数据库测试会产生空指针异常
- sql - 使用多个布尔运算符的 SQL 搜索
- javascript - 如何解析在javascript中嵌套了转义JSON的JSON?
- c# - 无法将 C# 类型正确代理到 F# WebSharper 应用程序中的客户端代码
- ruby - ocra 未初始化常量 CommonElement (NameError)
- python - Pandas 枢轴列顺序多个 agg