2011-04-09 125 views
0

我想在转换幻灯片的视图控制器中切换视图。我在网上找到了以下代码。幻灯片UIView转换

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

这个代码字很好,但是底部有一个非常恼人的白色条!我发现代码:

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

这似乎不工作。

所以,链接到的地方,我发现http://www.iphonedevsdk.com/forum/iphone-sdk-development/13427-uiview-slide-transition.html

+0

我很确定这段代码不是问题。 – Dair 2011-04-09 00:31:54

+0

@anon你认为那是什么? – 2011-04-09 00:33:41

回答

0

如果你没有显示状态栏,然后在屏幕的高度是480(状态栏为20个像素)。所以请尝试将其更改为CGRectMake(0,0,320,480)。

+0

Woah woah woah ...现在一切都变了... – 2011-04-09 01:45:06

+0

没关系 - 修理它。再次感谢你! – 2011-04-09 01:55:36

2

它需要480高,而不是460,但你应该改为使用PlayingView.frame = theWindow.bounds,而不是手动创建CGRect。它也可以用于通用应用程序或景观。

+0

非常感谢!!!! – 2011-04-09 01:56:14