Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
// get the view that's currently showing UIView *currentView = self.view; // get the the underlying UIWindow, or the view containing the current view view UIView *theWindow = [currentView superview];
// 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:kCATransitionFromLeft]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
Thank you for your help - this code was exactly what I was after. I removed the first couple of lines as I already had these set up as properties ;)
Just a quick note to anyone else who is also new to this, you will need to import the QuartzCore framework and add the appropriate #import line at the top of your code.
Thank you for your help - this code was exactly what I was after. I removed the first couple of lines as I already had these set up as properties ;)
Just a quick note to anyone else who is also new to this, you will need to import the QuartzCore framework and add the appropriate #import line at the top of your 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
//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:kCAMediaTimingFunctionEaseInEaseOut]];
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
//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:kCAMediaTimingFunctionEaseInEaseOut]];
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
//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:kCAMediaTimingFunctionEaseInEaseOut]];
// get the view that's currently showing UIView *currentView = self.view; // get the the underlying UIWindow, or the view containing the current view view UIView *theWindow = [currentView superview];
// 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:kCATransitionFromLeft]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
I have a couple questions about memory management using this code.
Assuming this is a method inside a UIViewController, when does this object get released? Its view isn't in the window anymore so it should be save to release right?
Who is retaining the newView's view controller? Where is it alloc-init-ed? If I want to initialized it from a nib, then load the view this way, will the view controller stick around beyond the end of this method?
Thanks very much for the code. I have some questions though. If I'm adding a second view, I noticed after going to the second view and going back to the root view, the screen goes white. I can only see it after deleting the line "[currentView removeFromSuperview];".
What I like to know, since the mainview is the rootview, is it necessary to remove it from view. How does this effect the memory?
And if I have to remove it from the root view, should I insert the same code on the 2nd view? As in adding a new subview? How would this effect the performance?
Hope this makes sense.
erastusnjuki;151083 said:
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
//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:kCAMediaTimingFunctionEaseInEaseOut]];
Hi there.. this is an old entry, but was hoping you can share your solution to the invalid references in the new viewcontroller.
This whole thread discusses something you should not do: hosting one view controller's view inside another view controller. The system is built around the idea that a view controller manages the entire screen.
The good news is that with iOS 5, it is now possible (easy, even) to do exactly what everybody here is trying to do.
You make one view controller the parent view controller. It adds all the view controllers that will display content inside it as child view controllers using the new addChildViewController method.
Then install a view controller's view as a subview of the parent view controller. When you're ready to swap it, use the new method transitionFromViewController:toViewController:duration:options:animations:completion:. That method includes several transtions "for free", and also takes an animation block that makes it trivial to do slides, cross-fades, and other transitions that change animatable view properties.
This whole thread discusses something you should not do: hosting one view controller's view inside another view controller. The system is built around the idea that a view controller manages the entire screen.
The good news is that with iOS 5, it is now possible (easy, even) to do exactly what everybody here is trying to do.
You make one view controller the parent view controller. It adds all the view controllers that will display content inside it as child view controllers using the new addChildViewController method.
Then install a view controller's view as a subview of the parent view controller. When you're ready to swap it, use the new method transitionFromViewController:toViewController:duration:options:animations:completion:. That method includes several transtions "for free", and also takes an animation block that makes it trivial to do slides, cross-fades, and other transitions that change animatable view properties.
Duncan,
Hello! I know this post is very old so hopefully you will receive an alert from the site regarding my question to you. That question being the following:
I'm using the method transitionFromViewController:toViewController in a UIViewController class, lets call this MyController. What I'm doing is in the tabBar delegate method tabBar:didSelectItem I'm detecting which tab is selected by the user. Then i'm reloading a tableView. The first 3 of the 5 tabs in this tabBar just display different data in the tableView. This all works perfectly however I would like to add a transition and/or some animation when a different tab is selected. I'm doing something wrong in this code, I think its because I'm using self.view for both the fromView and toView portions of the method... Code is below:
The transition takes place however the screen starts with my tableView_ displayed and turns to a black screen with nothing displayed.
Now - I can get a subset of the view to work if I do the following. First some info on how the view is setup.
I have a TableViewController named for example MyController.
MyController Contains a View Contains a TableView Contains custom TableViewCells Contains a Tab Bar Contains 5 TabBar Items (tabs) Contains a Navigation Bar Contains a left and right bar button.
@property (strong, nonatomic) IBOutlet UITableView *tableView; @property (strong, nonatomic) IBOutlet UITabBar *tabBar; @property (strong, nonatomic) IBOutlet UIView *myControllerView; // and a bunch of other stuff that is snipped out for this example @end
If in the .m file I replace
UIView *toView = self.view;
with
UIView *toView = tableView_;
It works, however the tabBar_ disappears. Not what I want because now the user is stuck on this page of the app.
If I try to use the View (myControllerView_ - which contains both the tableView_ and the tabBar_), I get the same broken results - a transition to a black screen.
UIView *toView = myControllerView_;
So, any Idea on what I'm doing wrong? Perhaps I'm going about this the wrong way?
Again, I would like the tableView_ to refresh when the [tableView_ reloadData] method is called but with an animation, and the tabBar_ must always be on the bottom of the View.
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThank you for your help - this code was exactly what I was after. I removed the first couple of lines as I already had these set up as properties ;)
Just a quick note to anyone else who is also new to this, you will need to import the QuartzCore framework and add the appropriate #import line at the top of your code.
Thanks ;)
Gee
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks for this! Worked perfectly :)
D.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI followed the above code and the view slides nicely. Though the new view never shows up.
In the "SwitchToView1" method I do the following:
[self.view addSubview:newView]
Plz, can someone let me know what I am missing.
Thanks.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI'm trying to slide a view out and a new one in but the code isn't working. did you get this to work?
asUwish.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome//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];
// 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]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAfter the transition any (IBAction) calls from the new view seem to crash the application...am I missing something here?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeManaged to get it to work, but this method seems to have a bunch of issues when it comes to orientation...
Wander if there is a way to get it to closer emulate presentModalViewController behaviour (i.e new view is animated with correct orientation and size)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAny advice is appreciated.
Thanks
Chris
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAssuming this is a method inside a UIViewController, when does this object get released? Its view isn't in the window anymore so it should be save to release right?
Who is retaining the newView's view controller? Where is it alloc-init-ed? If I want to initialized it from a nib, then load the view this way, will the view controller stick around beyond the end of this method?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat I like to know, since the mainview is the rootview, is it necessary to remove it from view. How does this effect the memory?
And if I have to remove it from the root view, should I insert the same code on the 2nd view? As in adding a new subview? How would this effect the performance?
Hope this makes sense.
www.lcgdi.com
"Learn and Play"
<a href="http://www.facebook.com/pages/Shah-Ala
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHi there.. this is an old entry, but was hoping you can share your solution to the invalid references in the new viewcontroller.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThe good news is that with iOS 5, it is now possible (easy, even) to do exactly what everybody here is trying to do.
You make one view controller the parent view controller. It adds all the view controllers that will display content inside it as child view controllers using the new addChildViewController method.
Then install a view controller's view as a subview of the parent view controller. When you're ready to swap it, use the new method transitionFromViewController:toViewController:duration:options:animations:completion:. That method includes several transtions "for free", and also takes an animation block that makes it trivial to do slides, cross-fades, and other transitions that change animatable view properties.
Duncan C
WareTo
Check out our apps in the Apple App store
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHello! I know this post is very old so hopefully you will receive an alert from the site regarding my question to you. That question being the following:
I'm using the method transitionFromViewController:toViewController in a UIViewController class, lets call this MyController. What I'm doing is in the tabBar delegate method tabBar:didSelectItem I'm detecting which tab is selected by the user. Then i'm reloading a tableView. The first 3 of the 5 tabs in this tabBar just display different data in the tableView. This all works perfectly however I would like to add a transition and/or some animation when a different tab is selected. I'm doing something wrong in this code, I think its because I'm using self.view for both the fromView and toView portions of the method... Code is below:
The transition takes place however the screen starts with my tableView_ displayed and turns to a black screen with nothing displayed.
Now - I can get a subset of the view to work if I do the following. First some info on how the view is setup.
I have a TableViewController named for example MyController.
MyController is defined like so:
If in the .m file I replace
with
It works, however the tabBar_ disappears. Not what I want because now the user is stuck on this page of the app.
If I try to use the View (myControllerView_ - which contains both the tableView_ and the tabBar_), I get the same broken results - a transition to a black screen.
So, any Idea on what I'm doing wrong? Perhaps I'm going about this the wrong way?
Again, I would like the tableView_ to refresh when the [tableView_ reloadData] method is called but with an animation, and the tabBar_ must always be on the bottom of the View.
Thanks in advance - hope you see this!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome