从右/左对presentModalViewController进行动画处理
目前我正在使用 [selfpresentModalViewController :newVCanimated:YES]
。我想从左/右/上/下呈现 newViewcontroller 并具有推送效果。我尝试使用 CATransition,但它在转换之间显示黑屏。
Currently I am using [self presentModalViewController :newVC animated:YES]
.I want to present newViewcontroller from left/right/top/bottom with a push effect. I tried to use CATransition but it displays a black screen in between the transition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
出现时:
解雇时:
When present:
When dismiss:
我也有同样的问题。假设您想从视图控制器 1 呈现视图控制器 2。在第一个视图控制器中使用
在第二个视图控制器中,在 viewWillAppear: 方法中添加代码
它将正常工作。如果再次出现黑屏,如果您使用的是导航控制器,请更换
为
I had the same problem. Say you want to present a view controller 2 from view controller 1. In the first view controller use
In the second view controller, in viewWillAppear: method add the code
It will work fine. If black screen comes again, if you are using navigation controller, replace
with
经过 X >= 4 小时的工作后,这将在没有“撕裂”或其他背景工件的情况下工作:
然后在 AppDelegate.swift 中:
这假设应用程序使用默认的故事板,并将初始 VC 作为 < code>UINavigationController
更新 swift 3/4
以及正在推送/取消的 VC 的transitioniningDelegate 实现:
After X >= 4 hours of work, this works without "tearing" or other background artifacts:
Then in
AppDelegate.swift
:This assumes an app is using the default storyboard with an initial VC as a
UINavigationController
Update for swift 3/4
And the transitioniningDelegate implementation for the VC being pushed/dismissed:
看起来很棘手,但只需几行代码即可完成。
首先,以模态方式呈现 LeftSlideViewController。您需要将 modalPresentationStyle 指定为 .overCurrentContext。
然后,打开 LeftSlideViewController。
从左侧移入(使用 CATransition)
隐藏 loadView 中的视图。
向 viewDidAppear 中的视图添加左移入过渡动画
向左移出(使用 UIView 动画)
使用 UIView 的动画对视图的框架进行动画处理动画完成后关闭 ViewController
It looks tricky, but make it done with just several lines of code.
First, Present LeftSlideViewController modally. You need to specify modalPresentationStyle to .overCurrentContext.
And then, Open LeftSlideViewController.
To move-in from left (Using CATransition)
Hide a view in loadView.
Add left-move-in transition animation to a view in viewDidAppear
To move-out to left (Using UIView animation)
Animate the view's frame by using UIView's animation and dismiss ViewController when the animation finished
UIModalTransitionStyles 只有四种:
例如:
There are only four UIModalTransitionStyles:
For example:
您可以在要呈现的视图控制器上设置一个
transitioningDelegate
。您必须遵守UIViewControllerTransitioningDelegate
和UIViewControllerAnimatedTransitioning
协议。通过实现 animateTransition(transitionContext: UIViewControllerContextTransitioning) ,您可以为视图控制器子视图设置动画。执行转换的函数
TransitionManager 如下所示:
You can set a
transitioningDelegate
on the view controller that you want to present. You must conform toUIViewControllerTransitioningDelegate
andUIViewControllerAnimatedTransitioning
protocols. And by implementinganimateTransition(transitionContext: UIViewControllerContextTransitioning)
you can animate either view controllers subviews.Function that performs transition
Then the TransitionManager looks like: