Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-15-2009, 04:00 PM   #1 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 3
Default UIView slide transition

Hi guys (and girls! )

I was wondering how I could achieve a slide left/right with a UIView?
I got the standard flip transition working using the following code:

// Flippin' marvellous!
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFl ipFromLeft forView:window cache:YES];

[[mainScreenController view] removeFromSuperview];
[window addSubview:[myNextScreenController view]];
[UIView commitAnimations];


I was wondering how would I modify this code to slide the second view in from right to left? (Sorry, I am a n00b to ObjC/iPhone atm!)

Thanks
Gee
gplumb is offline   Reply With Quote
Old 03-15-2009, 08:03 PM   #2 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,888
Default

Code:
// 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]];
	
	[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Old 03-22-2009, 07:52 AM   #3 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 3
Default

Hi Bertrand21

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.

Thanks
Gee
gplumb is offline   Reply With Quote
Old 04-02-2009, 04:51 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 33
Default

Quote:
Originally Posted by gplumb View Post
Hi Bertrand21

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.

Thanks
Gee

Thanks for this! Worked perfectly

D.
Duncster2k4 is offline   Reply With Quote
Old 07-31-2009, 05:04 PM   #5 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 3
Default

Hi,

I 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.
mihirsm is offline   Reply With Quote
Old 10-24-2009, 08:19 PM   #6 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 10
Default did you get this to work?

Hi there,

I'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.

Quote:
Originally Posted by mihirsm View Post
Hi,

I 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.
asUwish is offline   Reply With Quote
Old 12-11-2009, 06:10 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 1
Thumbs up Getting this to work

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"];

Last edited by erastusnjuki; 12-11-2009 at 06:12 AM.
erastusnjuki is offline   Reply With Quote
Old 04-12-2010, 01:59 PM   #8 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 2
Default Allowing for transitions back from target view...

Quote:
Originally Posted by erastusnjuki View Post
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"];
Hey guys, all this seems to work, just doesn't seem to create a valid reference to the new viewController.

After the transition any (IBAction) calls from the new view seem to crash the application...am I missing something here?
darkplastic is offline   Reply With Quote
Old 04-12-2010, 03:10 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 2
Default

Quote:
Originally Posted by darkplastic View Post
Hey guys, all this seems to work, just doesn't seem to create a valid reference to the new viewController.

After the transition any (IBAction) calls from the new view seem to crash the application...am I missing something here?
*EDIT*

Managed 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)
darkplastic is offline   Reply With Quote
Old 08-23-2010, 06:59 AM   #10 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 19
Default

Quote:
Originally Posted by darkplastic View Post
*EDIT*

Managed 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)
How did you manage to work around this problem darkplastic? I'm struggling with making IBAction calls too.

Any advice is appreciated.

Thanks

Chris
chrigil is offline   Reply With Quote
Old 10-14-2010, 05:33 AM   #11 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: barcelona
Posts: 3
Default THANK YOU!!!!!!

THANK YOU!!!!!!

Quote:
Originally Posted by erastusnjuki View Post
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"];
agfa555 is offline   Reply With Quote
Old 11-05-2010, 02:26 AM   #12 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 11
Default

Quote:
Originally Posted by Bertrand21 View Post
Code:
// 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]];
	
	[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
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?
aoberoi is offline   Reply With Quote
Old 05-26-2011, 10:48 PM   #13 (permalink)
iOS padawan
 
Hakimo's Avatar
 
Join Date: Apr 2011
Posts: 12
Default

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.

Quote:
Originally Posted by erastusnjuki View Post
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"];
__________________
www.hakimo-studio.com
www.lcgdi.com
"Learn and Play"
Facebook | Twitter
Our Apps : Pocket Ipin
Hakimo is offline   Reply With Quote
Old 01-22-2012, 10:47 AM   #14 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 4
Default

Quote:
Originally Posted by darkplastic View Post
Hey guys, all this seems to work, just doesn't seem to create a valid reference to the new viewController.

After the transition any (IBAction) calls from the new view seem to crash the application...am I missing something here?

Hi there.. this is an old entry, but was hoping you can share your solution to the invalid references in the new viewcontroller.
dynamite88 is offline   Reply With Quote
Old 01-22-2012, 01:44 PM   #15 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,749
Default

Quote:
Originally Posted by dynamite88 View Post
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:dura tionptions: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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
slide, transition, uiview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 448
12 members and 436 guests
clerisysolutions, dana0550, dapis, darbsllim, dre, Harolano, Hyde, lbert, leesdesjardins, marshusensei, Objective Zero, RickSDK
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 157,851
Threads: 88,914
Posts: 379,294
Top Poster: BrianSlick (7,072)
Welcome to our newest member, darbsllim
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:09 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0