开发者

iPhone - animating a view controller presentation

I have a UINavigationControl and I would like to present a view controller pushing it from the top and removing it from the view pushing it to the top.

Is there a way to change the default animation used when you call

[self.navigationController pushViewController:myViewController animated:YES];

to another animat开发者_开发问答ion instead of pushing right to left or do I have to animate it myself?

In the second case, how do I do that?

thanks.


Import Quartzcore framework add header line in .h file

#import <QuartzCore/QuartzCore.h>

than where you need to call next viewController, just add this animation line

CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.2f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.view layer] addAnimation:animation forKey:@"pushIn"];

Here is call to view controller and add in super view, when you BACK TO this view, just add same animation maintain only left and right, than set removeFromSuperView..

classObj = [[ClassController alloc] initWithNibName:@"Xib Name" bundle:[NSBundle mainBundle]];
[self.view addSubview:classObj.view];


Here is an excellent tutorial on creating your own animations for your UIViews.

http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_intro/chapter_1_section_1.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜