ViewController *vc = [[ViewController alloc] init];
CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionPush;//可更改为其他方式
transition.subtype = kCATransitionFromLeft;//可更改为其他方式
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:vc animated:NO];
[vc release];
通常在viewcontroller之间切换的时候都是从右面进入,上面的方法实现了从左进行切换效果,也可以配置为上,(下或右可以用系统自带的)上面的效果是从左push进入,要配置两个参数,下面是文档上描述的,一块拿来了。。
Common Transition Types
These constants specify the transition types that can be used with the type property.
NSString * const kCATransitionFade;
NSString * const kCATransitionMoveIn;
NSString * const kCATransitionPush;
NSString * const kCATransitionReveal;
Constants
kCATransitionFade
The layer’s content fades as it becomes visible or hidden.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.
kCATransitionMoveIn
The layer’s content slides into place over any existing content. The “Common Transition Subtypes”
are used with this transition.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.
kCATransitionPush
The layer’s content pushes any existing content as it slides into place. The “Common Transition
Subtypes” are used with this transition.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.
kCATransitionReveal
The layer’s content is revealed gradually in the direction specified by the transition subtype.
The “Common Transition Subtypes” are used with this transition.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.
Declared In
CATransition.h
Common Transition Subtypes
These constants specify the direction of motion-based transitions. They are used with the subtype
property.
NSString * const kCATransitionFromRight;
NSString * const kCATransitionFromLeft;
NSString * const kCATransitionFromTop;
NSString * const kCATransitionFromBottom;
Constants
kCATransitionFromRight
The transition begins at the right side of the layer.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.
kCATransitionFromLeft
The transition begins at the left side of the layer.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.
kCATransitionFromTop
The transition begins at the top of the layer.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.
kCATransitionFromBottom
The transition begins at the bottom of the layer.
Available in iOS 2.0 and later.
Declared in CAAnimation.h.