iOS Dismiss and Present view controller custom ani

2019-03-22 09:27发布

I have a view controller that I am presenting with the following objective c code:

CATransition *animation=[CATransition animation];
animation.delegate=self;
animation.duration=0.3;
animation.type=kCATransitionMoveIn;
animation.subtype=kCATransitionFromRight;

[self presentViewController:reader animated:NO completion:nil];
[reader.view.layer addAnimation:animation forKey:@"animation"];

and dismissing with similar code inside a delegate method

CATransition *animation=[CATransition animation];
animation.delegate=self;
animation.duration=0.3;
animation.type=kCATransitionMoveIn;
animation.subtype=kCATransitionFromLeft;

[self dismissViewControllerAnimated:NO completion:nil];
[self.view.layer addAnimation:animation forKey:@"animation"];

However there is one problem: unlike using a navigation controller where you see one view slide onto other view; here the old view just disappears instantly so the new view moves onto a blank view.

How do I fix this problem? I need this code to work in IOS 6,7 and 8 and would like it to look like the horizontal animation you see when going back and forth between views that are inside navigation controllers.

Edit: The solution I accepted has a bug with iOS 6, if I can find a solution that fixes it, I'll edit this post.

Edit 2: Found it. It appears that since I am presenting a zBar view controller I need to use this code

zbarController.wantsFullScreenLayout=NO;

after I set the cameraOverlayView.

1条回答
贼婆χ
2楼-- · 2019-03-22 10:09

Presenting a view controller using a custom animation:

CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:reader animated:NO];

Dismissing a view controller using a custom animation:

CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];    
[self.navigationController popViewControllerAnimated:NO];
查看更多
登录 后发表回答