我目前正在尝试为ListView内的ViewCell设置动画,以便一旦被点击便会展开和折叠。其背后的逻辑工作正常,但似乎无法解决iOS ListView的问题。目前,该实现是通过共享代码完成的,而不是特定于平台的。
ViewCell本身包含两个子视图:
<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="com.example.CollapsableCell"
Appearing="OnAppearing">
<Frame x:Name="CollapsableFrame" CornerRadius="5" HasShadow="true" Margin="5" BorderColor="Gray" OutlineColor="Gray">
<Grid>
<Grid x:Name="CollapsableContent" />
</Grid>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped" />
</Frame.GestureRecognizers>
</Frame>
</ViewCell>
在折叠视图和展开视图之间切换的方法如下:
protected void OnTapped(object sender, EventArgs args)
{
Debug.WriteLine("OnTapped");
if (_isExpanded) // collapse the ViewCell
{
CollapsableFrame.LayoutTo(_collapsedBounds, 500, Easing.CubicIn);
ForceUpdateSize();
CollapsableFrame.BackgroundColor = _collapsedView.BackgroundColor;
_collapsedView.RotationY = -270.0;
_expandedView.RotateYTo(-90.0, 250, Easing.SinIn);
_expandedView.IsVisible = false;
_collapsedView.IsVisible = true;
_collapsedView.RotateYTo(-360.0, 250, Easing.SinOut);
_collapsedView.RotationY = 0.0;
_isExpanded = false;
}
else // Expand the ViewCell
{
CollapsableFrame.LayoutTo(_expandedBounds, 500, Easing.CubicOut);
ForceUpdateSize();
CollapsableFrame.BackgroundColor = _expandedView.BackgroundColor;
_expandedView.RotationY = -270.0;
_collapsedView.RotateYTo(-90.0, 250, Easing.SinIn);
_collapsedView.IsVisible = false;
_expandedView.IsVisible = true;
_expandedView.RotateYTo(-360.0, 250, Easing.SinOut);
_expandedView.RotationY = 0.0;
_isExpanded = true;
}
}
_collapsedView和_expandedView是通过属性设置的私有成员,并且是CollapsableContent的子对象,
在Android上,这非常完美,在iOS上,CollapsableFrame的缩放永远无法正常工作(内容超出了Frames的边界),此外,在执行动画几次后,动画被卡住并冻结了整个应用程序。我已经尝试过将动画缩小到CollapsableFrame的缩放比例,但是问题仍然存在。
以下是我的开发环境的信息:
Visual Studio Community 2017 for Mac
Version 7.6 (build 2190)
Installation UUID: 42ba26db-6c15-44b2-a48a-811339d08d89
Runtime:
Mono 5.12.0.301 (2018-02/4fe3280bba1) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)
Package version: 512000301
NuGet
Version: 4.3.1.4445
.NET Core
Laufzeit: /usr/local/share/dotnet/dotnet
Laufzeitversionen:
2.1.2
2.1.1
SDK: /usr/local/share/dotnet/sdk/2.1.302/Sdks
SDK-Versionen:
2.1.302
2.1.301
MSBuild-SDKs: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/msbuild/15.0/bin/Sdks
Xamarin.Profiler
Version: 1.6.3
Speicherort: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Apple Developer Tools
Xcode 9.4.1 (14161)
Build 9F2000
Xamarin.Mac
Version: 4.6.0.13 (Visual Studio Community)
Hash: 373c313a
Branch:
Build date: 2018-07-24 23:47:12-0400
Xamarin.iOS
Version: 11.14.0.13 (Visual Studio Community)
Hash: 373c313a
Branch: HEAD
Build date: 2018-07-24 23:47:12-0400
Xamarin.Android
Version: 9.0.0.18 (Visual Studio Community)
Android SDK: /Users/ban/Library/Developer/Xamarin/android-sdk-macosx
Unterstützte Android-Versionen:
8.1 (API-Ebene 27)
Version von SDK Tools: 26.1.1
Version der SDK-Plattformtools: 28.0.0
Version der SDK-Buildtools: 27.0.3
Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
Android Designer EPL-Code ist hier verfügbar:
https://github.com/xamarin/AndroidDesigner.EPL
Xamarin Inspector
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1
Build Information
Release ID: 706002190
Git revision: 329690594b336b0b810b0399136d55eb54d292ec
Build date: 2018-08-20 12:03:11+00
Build branch: release-7.6
Xamarin extensions: 23b59d33e3e5e6b7efa0f6d2d699867ab5082527
Operating System
Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
Thu Jun 21 22:53:14 PDT 2018
root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
我认为我必须在iOS上使用自定义渲染器来解决此问题,但目前我不知道从哪里开始。我希望社区中的某人可以给我提示。
答案 0 :(得分:0)
这是Xamarin.Forms团队正在调查的正式问题: https://github.com/xamarin/Xamarin.Forms/issues/4012