2011-04-09 121 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