Theme
Theme

Reputation: 417

Slide UIView Transitions

I want to switch views in a viewcontroller with a transition slide. I found the following code online.

//  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:PlayingView]; 
PlayingView.frame = CGRectMake(0, 0, 320, 460);
//  set  up  an  animation  for  the  transition  between  the  views 
CATransition *animation = [CATransition animation]; 
[animation setDuration:1]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromLeft]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; 

This code words great but there is a VERY annoying white strip on the bottom! I found the code:

  PlayingView.frame = CGRectMake(0, 0, 320, 460);

which doesn't seem to work.

So, the link to the place I found http://www.iphonedevsdk.com/forum/iphone-sdk-development/13427-uiview-slide-transition.html

Upvotes: 0

Views: 5015

Answers (2)

Peter DeWeese
Peter DeWeese

Reputation: 18333

It needs to be 480 high, not 460, but you should instead use PlayingView.frame = theWindow.bounds instead of manually creating the CGRect. It'll also work in a universal app or for landscape.

Upvotes: 2

Casey
Casey

Reputation: 2403

If you're not displaying the status bar then the height of the screen is 480 (the status bar is 20 pixels). So try changing it to CGRectMake(0, 0, 320, 480).

Upvotes: 0

Related Questions