iOS Dismiss和Present视图控制器自定义动画 [英] iOS Dismiss and Present view controller custom animation

查看:225
本文介绍了iOS Dismiss和Present视图控制器自定义动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图控制器,我正在使用以下目标c代码:

  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];

并在委托方法中解雇类似代码

  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];

但是有一个问题:与使用导航控制器不同,你可以看到一个视图滑动到其他视图上;这里旧视图立即消失,因此新视图将
移动到空白视图上。



如何解决此问题?我需要这个代码在IOS 6,7和8中工作,并希望它看起来像你在导航控制器内的视图之间来回看时的水平动画。



编辑:
我接受的解决方案有iOS 6的错误,如果我能找到修复它的解决方案,我会编辑这篇文章。



<编辑2:
找到它。看来,因为我提出了一个zBar视图控制器,我需要使用这个代码

  zbarController.wantsFullScreenLayout = NO;设置cameraOverlayView后,

解决方案

使用自定义动画呈现视图控制器:

  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];

使用自定义动画解雇视图控制器:

  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];


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.

解决方案

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];

这篇关于iOS Dismiss和Present视图控制器自定义动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆