[英]iOS Swift: Transition Animation on same View Controller
How can I get a Transition Animation
effect(like a page slide) on a single View Controller - so that it looks like i am transitioning to a new page/controller
(although only data is changing in the same view)? 如何在单个视图控制器上获得Transition Animation
效果(如页面幻灯片) - 这样看起来我正在转换到new page/controller
(尽管只有数据在同一视图中更改)?
For example: I have a UIViewController
that has Previous and Next buttons. 例如:我有一个UIViewController
,它有Previous和Next按钮。 On clicking Next these buttons, a different Title and Image is displayed on the ' same ' UIViewController
. 单击“下一步”按钮,“ 相同 ”的UIViewController
上将显示不同的“标题和图像”。
I know this can be done with UIPageViewController
- but I am new to iOS, and find it rather difficult to implement that way. 我知道这可以用UIPageViewController
完成 - 但我是iOS的新手,并且发现它很难以这种方式实现。
I have the same case on this. 我对此有相同的理由。 But because we don't expect a complicated slide animation so I wouldn't implement the UIPageViewController. 但是因为我们不期望复杂的幻灯片动画所以我不会实现UIPageViewController。 Instead, I came up with the below solution: 相反,我提出了以下解决方案:
The idea is creating a snapshot view and start the animation on it, also update the view with new data at the moment user start to swipe. 我们的想法是创建快照视图并在其上启动动画,同时在用户开始刷卡时使用新数据更新视图。 By doing it, we can make it feel like we are transiting to another view. 通过这样做,我们可以让我们觉得我们正在转向另一种观点。
Sample code below was written in Xamarin.iOS but I believe it can be transfered to Swift/Obj-C easily: 下面的示例代码是用Xamarin.iOS编写的,但我相信它可以很容易地转移到Swift / Obj-C:
UIView snapShotView = View.SnapshotView(false); // Create snapshot for the view (I assumed that View is the container) View.Add(snapShotView); snapShotView.Frame = View.Frame; //Add snapshot and set its frame so the snapshot will be overlapped the original View CGRect snapshotEndFrame = snapShotView.Frame; snapshotEndFrame.X = -snapShotView.Frame.Width; UIView.Animate(0.7, 0, UIViewAnimationOptions.CurveEaseInOut, () => { //Load new data to your View ... //Animate the snapshot view snapShotView.Frame = snapshotEndFrame; }, () => { //Remove Snap Shot View after doing animation to prevent memory leak snapShotView.RemoveFromSuperview(); snapShotView.Dispose(); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.