Gre*_*tic 7 iphone uiviewcontroller screen-orientation
我的应用程序有大约10个不同的UIViewControllers,其中一个我想在旋转设备时切换到横向模式.(其余的,我想保持肖像.)
为了在那个视图上实现旋转,我需要实现其控制器的'shouldAutorotate'方法并返回YES.由于这个视图是通过导航控制器访问的,我还需要创建一个UINavigationController的子类,它实现'shouldAutorotate'并返回YES.
这个解决方案很有效,但也很好.我发现我推到UINavigationController的子类上的所有UIViewControllers都会响应旋转,即使我实现'shouldAutorotate'并返回NO.(记住:我只希望一个特定的UIViewController响应旋转,而不是导航控制器堆栈中的每一个.)
所以,我的问题是:我该如何做到最好?我能提出的所有解决方案似乎都很麻烦,2)更糟糕,似乎没有用.
非常感谢.
我见过使用您的方式进行操作的示例,但无法使其正常工作。我从苹果的例子中找到了更好的方法。基本上你实现了一个presentModalViewController并创建另一个视图。UIKit 执行基本的旋转动画并在视图之间淡入淡出。您必须将旋转视图实现为委托类,以便它可以回调到其调用类以关闭它并更新方向。
- (void)orientationChanged:(NSNotification *)notification
{
// We must add a delay here, otherwise we'll swap in the new view
// too quickly and we'll get an animation glitch
NSLog(@"orientationChanged");
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
Run Code Online (Sandbox Code Playgroud)
然后显示横向屏幕:
- (void)updateLandscapeView
{
PortraitView *portraitView = [[PortraitView alloc] init];
portraitView.delegate = self;
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController: portraitView animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
[portraitView release];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11020 次 |
| 最近记录: |