我想在视图控制器中使用转换幻灯片切换视图。我在网上找到了以下代码。
// 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 :(得分:2)
它需要480高,而不是460,但您应该使用PlayingView.frame = theWindow.bounds
而不是手动创建CGRect。它也适用于通用应用程序或景观。
答案 1 :(得分:0)
如果您没有显示状态栏,则屏幕高度为480(状态栏为20像素)。所以尝试将其更改为CGRectMake(0,0,320,480)。