简体   繁体   English

iOS呈现动画为“推”的视图控制器(左右动画)

[英]iOS presenting view controller animated as 'Push' (right-left animation)

Currently, I have a view controller presenting other view controller. 当前,我有一个显示其他视图控制器的视图控制器。 What I'm trying to do is to recreate the default animation used when pushing a view controller. 我想做的是重新创建推视图控制器时使用的默认动画。

My current approach is: 我当前的方法是:

FirstViewController : FirstViewController

@IBAction private func push(sender: AnyObject) {
    let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SecondViewController")

    let transition = CATransition()
    transition.duration = 0.5
    transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromRight

    view.window?.layer.addAnimation(transition, forKey: kCATransition)

    presentViewController(vc, animated: false, completion: nil)
}

SecondViewController : SecondViewController

@IBAction private func pop(sender: AnyObject) {

    let transition = CATransition()
    transition.duration = 0.5
    transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromLeft

    view.window?.layer.addAnimation(transition, forKey: kCATransition)

    dismissViewControllerAnimated(false, completion: nil)
}

It is almost working, but I have a weird behaviour, I'm having a kind of black screen/flash when transitioning between view controllers. 它几乎可以正常工作,但是我有一个奇怪的行为,在视图控制器之间进行转换时,我有一种黑屏/闪光灯。 I already tried changing window.backgroundColor but it is not fixing the issue. 我已经尝试过更改window.backgroundColor但是它不能解决问题。

Thanks in advance 0_0... 在此先感谢0_0 ...

The trouble is merely that what you're doing is not how to customize the animation for a present/dismiss transition. 问题仅在于您在做什么,而不是如何为当前/关闭过渡自定义动画。 Apple has provided you with a clear, well-establish, official way to do that, and what you're doing is not it. Apple为您提供了一种清晰,完善的官方方法来执行此操作,而您要做的不是。 You need to give your presented view controller a transitioningDelegate along with implementations of animationControllerForPresentedController: and animationControllerForDismissedController: , and implement the UIViewControllerAnimatedTransitioning protocol, possibly along with a custom UIPresentationController subclass. 您需要为呈现的视图控制器提供一个transitioningDelegate以及animationControllerForPresentedController:animationControllerForDismissedController:实现,并实现UIViewControllerAnimatedTransitioning协议(可能还有一个自定义UIPresentationController子类)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 呈现具有透明度和动画的视图控制器 - Presenting a view controller with transparency and animation 单个视图的iOS动画从左到右 - iOS animation of single View left to right 从呈现视图控制器推送视图控制器 - Push View Controller from Presenting View Controller iOS 使用从左到右的动画取消隐藏视图 - iOS unhide view with left to right animation 在iOS上使用动画从右到左调整视图大小 - Resize view right-to-left with animation on iOS iOS:旋转iphone后,仅从支持肖像模式的视图控制器以横向显示视图控制器 - iOS: Presenting a view controller in landscape right from a view controller supporting only portrait mode after rotating the iphone 呈现视图 controller 在 animation 之后消失 - Presenting View controller disappears after animation 呈现具有透明背景且从左到右过渡的新视图控制器时出现问题 - Issue while presenting New View controller having Transparent Background with Transition from Left to right 如何自定义Modal View Controller呈现动画? - How to custom Modal View Controller presenting animation? 推动视图控制器时“从左到右”的无缝动画? - Seamless animation "from left to right" when pushing view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM