December 21, 2009
iPhone Dev: Adding the slide transition between views
The slide transition that’s used in the navigation controller is not a standard iPhone SDK transition. To add the slide transition (from right) between different UIViews use the following code
//1. Add the QuatzCore Framework from library to the Frameworks folder
//2. At the top include the header file#import
//3. Implement the code
yourViewController = [[YourViewController alloc]
initWithNibName:@”YourViewController” bundle:nil];//4. Add the transition in the method that moves to the next view
// get the view that’s currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];UIView *newView = yourViewController.view;
// remove the current view and replace with myView1
[currentView removeFromSuperview];
[theWindow addSubview:newView];// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];//5. The key is any unique string. From the CALayer class reference.
//key = “A string that specifies an identifier for the animation. Only one animation
//per unique key is added to the layer. The special key kCATransition is automatically
//used for transition animations. The nil pointer is also a valid key.”
[[theWindow layer] addAnimation:animation forKey:@”SwitchToNextView”];
Thanks to the participants at iphonedevsdk.com
Comments Off