使用UITabBar在iOS 6中自动旋转单个UIViewController [英] Autorotate a single UIViewController in iOS 6 with UITabBar
问题描述
我有一个仅适用于纵向模式
的应用,但是有一个可以显示视频的单一视图,所以我希望该视图也能在<$ c $中工作c>横向模式,但是在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中.mi有:
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屋!