在 Xamarin.Forms iOS 中将子视图内容添加为 ScrollView 时,在平移 y 位置后,AbsoluteLayout 子布局边界未正确更新。
[XAML]
<AbsoluteLayout AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="SizeProportional"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="LightBlue">
<local:CustomView x:Name="viewcustom" AbsoluteLayout.LayoutFlags="SizeProportional"
AbsoluteLayout.LayoutBounds="0,0,1,1" BackgroundColor="LightGray">
<ScrollView x:Name="scrollView" >
<StackLayout BackgroundColor="Red">
<Button Margin="10" Text="Button 1" />
<Button Margin="10" Text="Button 2" />
<Button Margin="10" Text="Button 3"/>
<Button Margin="10" Text="Button 4"/>
<Button Margin="10" Text="Button 5"/>
<Button Margin="10" Text="Button 6"/>
<Button Margin="10" Text="Button 7"/>
<Button Margin="10" Text="Button 8"/>
<Button Margin="10" Text="Button 9"/>
<Button Margin="10" Text="Button 10"/>
<Button Margin="10" Text="Button 11"/>
<Button Margin="10" Text="Button 12"/>
<Button Margin="10" Text="Button 13"/>
<Button Margin="10" Text="Button 14"/>
<Button Margin="10" Text="Button 15"/>
</StackLayout>
</ScrollView>
</local:CustomView>
</AbsoluteLayout>
[CustomViewRenderer.cs]
private void OnPanning()
{
var currentY = this.panGesture.TranslationInView(this).Y;
Double screenHeigth = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
switch (this.panGesture.State)
{
case UIGestureRecognizerState.Changed:
DependencyService.Get<IAnimate>().TranslateYTo(this.view, this.prevTranslatedY, currentY, 300);
UpdateHeight(currentY, 0);
break;
case UIGestureRecognizerState.Ended:
...
DependencyService.Get<IAnimate>().TranslateYTo(this.view, this.prevTranslatedY, currentY, 300);
UpdateHeight(currentY, 0);
...
break;
}
}
private void UpdateHeight(double y, double viewY) //&& this.backdrop.IsBackLayerRevealed && !isPanningEnabled
{
Double screenHeigth = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
var heightPercentage = (screenHeigth - y) / screenHeigth;
Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(view, new Xamarin.Forms.Rectangle(0, viewY, 1, heightPercentage));
}
鼠标点拖动视图
由于边界未正确更新,视图无法用鼠标拖动。
VS 2019 测试设备:iPhone模拟器 XF 版本:4.8