Dim*_*lov 11 iphone animation uiviewcontroller ios swift
我的目标是在第一个视图控制器中启动平滑动画,在第二个视图控制器中结束.
我正在尝试使用符合UIViewControllerAnimatedTransitioning
和UIViewControllerTransitioningDelegate
协议的对象的过渡动画 .我在故事板中设置了两个视图控制器(VC)并将它们与segue连接(默认显示).我还在第一个VC中展开了segue方法,并在第二个VC中为它设置了一个按钮.
我有奇怪的问题.我的对象有方法
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
self.presenting = true
NSLog("start")
return self
}
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
if presenting {
NSLog("Animation Push")
transitionPush(transitionContext)
}
else {
NSLog("Animation Pop")
transitionPop(transitionContext)
}
}
Run Code Online (Sandbox Code Playgroud)
我有两种不同的动画方法,从第一个VC到第二个VC,从第二个到第一个VC.当我激活segue时,我animationControllerForPresentedController
和animateTransition
方法之间有很奇怪的延迟.有时它可能是大约1秒,我的整个过渡动画必须是1秒加上这个意想不到的延迟太大了.这是一个日志:
2015-02-08 19:52:33.528 MyApp[1318:119598] start
2015-02-08 19:52:33.979 MyApp[1318:119598] Animation Push
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会出现这种延迟,是否有办法删除或减少它?我试图检查这是否是我的代码,但我没有找到任何证据.随意询问更多信息.
我有同样的问题。您可能没有从主线程(presentViewController 调用)触发动画。
这为我解决了这个问题(Objective-C 代码):
dispatch_async(dispatch_get_main_queue(),
^{
[self presentViewController:viewControllerToPresent
animated:YES
completion:nil];
});
Run Code Online (Sandbox Code Playgroud)