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

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

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, 03: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, 07:03 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 469
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"];
__________________
Bertrand21 is offline   Reply With Quote
Old 03-22-2009, 06: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, 03:51 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 27
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, 04: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, 07:19 PM   #6 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 7
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, 05: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 05:12 AM.
erastusnjuki is offline   Reply With Quote
Old 04-12-2010, 12: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, 02: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
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
» Stats
Members: 41,862
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
Welcome to our newest member, futurevilla216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0