Quote:
Originally Posted by dynamite88
Hi All,
I want to be able to switch from screen to screen created from the same view controller with the sliding left/right transition. So far I've tried the solution posted on this forum does not work for me ( reference):
Code:
Just for those who are stranded like I was ...here's some code that worked for me. with this the new view slid in
//1. Add the QuatzCore Framework from library to the Frameworks folder
//2. At the top include the header file
#import <QuartzCore/QuartzCore.h>
//3. Implement the code
yourViewController = [[YourViewController alloc]
initWithNibName:@"YourViewController"
bundle:nil];
// 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:kCAMediaTimingFunctionEaseInEaseO ut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
I also checked out another sample from Apple: Apple sample code
The two samples above do not slide to a view with interactions. I haven't been able to find a good example where we could possibly continually keep sliding left to a new screen without crashing (I get stuck on the first new screen since references to the IBActions are lost)? Any ideas on how to accomplish this?
Thanks in advance!
-J
|
Do you mean that you want to transition from one view controller to a different instance of the same view controller that displays different content?
Or are you trying to have a single instance of a view controller that manages multiple pages as views, and slides from one to the next?
If the second, do you have a small, fixed number of views that you want to display, or do you want to be able to display an arbitrary number of views?
The first approach might be a lot simpler than the second. Create a new instance of your view controller, set a custom transition, and push it onto a navigation controller. (or use a Segue if you're using Storyboards.)