使用 UITabBar 在 iOS 6 中自动旋转单个 UIViewController [英] Autorotate a single UIViewController in iOS 6 with UITabBar
问题描述
我有一个只能在 Portrait Mode
下工作的应用程序,但有一个可以显示视频的 singleView,所以我希望该视图也能在 landscape 模式
下工作,但在 iOS 6 中我不知道如何做到这一点,现在我有了这个:
I have an app that work only in Portrait Mode
, but there is a singleView that can display video, so i want that view work also in the landscape mode
, but in iOS 6 I can't figure out how I can do it, now I have this:
在 AppDelegate.m 中,我有:
In AppDelegate.m i have:
self.window.rootViewController = myTabBar;
然后在项目摘要中:
我发现在 iOS 6 中要检测视图旋转,我必须这样做:
and i found that in iOS 6 to detect the view rotation i have to do this:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return YES;
}
所以我只在我的 UIViewController
中插入上面的代码,我也想在横向中使用它,但不起作用,有人知道我该怎么做吗?我只想要显示视频时自动旋转.
so i insert the code above only in my UIViewController
that I want use also in landscape, but don't work, anyone knows how i can do it? i just want the autorotate when show video.
推荐答案
首先,您的目标设置应如下所示:
Firstly, your target settings should look like this:
在 UITabBarController 中:
In UITabBarController:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
-(NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
在您的 ViewController 中:
Inside your ViewController:
a) 如果您不想旋转:
a) if you dont want to rotate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
b) 如果你想旋转到横向:
b) if you want to rotate to landscape:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
其他解决方案是在 AppDelegate 内部实现这个方法:
Other solution is to implement this method inside AppDelegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations = UIInterfaceOrientationMaskAll;
if (self.window.rootViewController) {
UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presented supportedInterfaceOrientations];
}
return orientations;
}
这篇关于使用 UITabBar 在 iOS 6 中自动旋转单个 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!