简体   繁体   English

iOS Swift:在同一个View Controller上进行过渡动画

[英]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.

相关问题 如何使用手势快速iOS过渡到视图控制器 - How to transition to a view controller with gesture swift iOS iOS 7当前的视图控制器具有不带动画的自定义过渡 - iOS 7 present view controller with custom transition without animation iOS Swift,返回到视图控制器的相同实例 - iOS Swift, returning to the same instance of a view controller iOS Swift总是以相同的视图控制器启动 - iOS Swift always start with same view controller 多视图1视图控制器过渡动画 - Multiple Views 1 View Controller transition animation 自定义视图控制器过渡动画的时间安排? - Customize view controller transition animation timing? 将动画从一个视图控制器过渡到另一个视图控制器 - Transition animation from one view controller to another view controller 同一视图控制器中的AWS AppSync多个订阅不起作用-iOS Swift - AWS AppSync multiple subscriptions in same view controller not working - iOS Swift iOS 11:使用带有不透明导航栏的导航控制器内的scrollView的弹出视图控制器在过渡期间导致奇怪的内容动画 - iOS 11: Pop view controller with scrollView inside navigation controller with opaque navbar result in weird content animation during transition 带选项卡视图控制器的Xcode IOS过渡视图 - Xcode IOS transition views with a tab view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM