How to custom Modal View Controller presenting animation?

痴心易碎 提交于 2019-11-27 00:11:24

问题


Instead of setting uiviewcontroller's modalTransitionStyle, I want to add an CAAnimation(or some other thing). This code can perform an custom animation in navigationController

CATransition* transition = [CATransition animation];
          transition.duration = 0.4;
          transition.type = kCATransitionFade;
          transition.subtype = kCATransitionFromBottom;
          [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
          [self.navigationController pushViewController:adjustViewController animated:NO];

How can I implement it to a Modal View Controller?


回答1:


You just need to add the transition to the window's layer, and present your controller rather than pushing it:

     CATransition* transition = [CATransition animation];
     transition.duration = 1;
     transition.type = kCATransitionFade;
     transition.subtype = kCATransitionFromBottom;
     [self.view.window.layer addAnimation:transition forKey:kCATransition];
     [self presentViewController:adjustViewController animated:NO completion:nil];



回答2:


Swift Version

let viewController = YourViewController()
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionFade
transition.subtype = kCATransitionFromBottom
view.window!.layer.add(transition, forKey: kCATransition)
present(viewController, animated: false, completion: nil)



回答3:


From apple develop guide:

Presenting a View Controller Using Custom Animations

To present a view controller using custom animations, do the following in an action method of your existing view controllers:

  • Create the view controller that you want to present.

  • Create your custom transitioning delegate object and assign it to the view controller’s transitioningDelegate property. The methods of your transitioning delegate should create and return your custom animator objects when asked.

  • Call the presentViewController:animated:completion: method to present the view controller.

...



来源:https://stackoverflow.com/questions/19931710/how-to-custom-modal-view-controller-presenting-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!