好了!我终于在iOS 5中解决了我的选项卡栏旋转问题,但是iOS 6和xcode似乎破坏了一些东西……这就是我所拥有的:
目标应用程序摘要包括:支持的界面方向- Portraint、横向左侧、横向右侧
App中的每个单独的View都有以下方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return ((interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown) &&
(interfaceOrientation != UIInterfaceOrientationLandscapeLeft) &&
(interfaceOrientation != UIInterfaceOrientationLandscapeRight));
} else {
return YES;
}
}
- (BOOL)shouldAutorotate
{
NSLog(@"am I called1?");
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
NSLog(@"am I called?");
return UIInterfaceOrientationMaskPortrait;
}
在不属于选项卡栏的视图中,旋转被阻止。在选项卡栏的所有视图(共有5个)中,应用程序从不调用ShouldAutorotate,因此会进行旋转。当一个视图加载时,supportedInterfaceOrientations似乎只调用一次,但如果我在视图之间切换,就不会调用它,因为我得到了NSLog,但它似乎忽略了MaskPortrait设置。
我必须让目标中的景观处于启用状态,因为我有一个需要旋转的视频播放器视图(它确实可以这样做,很好)
这是iOS 6中的选项卡栏错误吗?是否需要以不同的方式禁用视图的旋转?在iOS5中,应该自动切换到界面的导向效果很好
我已经做了一段时间了
谢谢,扎克
发布于 2012-09-21 15:37:53
扎克我也遇到过同样的问题。这是因为您将viewController嵌入到了TabBar控制器或UINavigationController中,而对这些方法的调用是在这些方法内部进行的,而不是您的普通视图(在iOS6中进行了更改)。
我遇到这个问题是因为我在我的所有模式视图上展示了一个嵌入在UINavigationController中的viewController,这些模式视图都有导航到不同的视图(注册过程、登录等)。
我的简单解决方法是为UINavigationController创建一个包含这两个方法的类别。我让shouldAutorotate返回NO,因为我不想让我的模式视图旋转。你的解决方法可能就是这么简单,试一试。希望能有所帮助。
我创建了一个类别并将其命名为autoRotate,并选择了theUINavigationController选项。M+H文件如下所示。
#import "UINavigationController+autoRotate.h"
@implementation UINavigationController (autoRotate)
-(BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
@end
..。和类别.h:
#import <UIKit/UIKit.h>
@interface UINavigationController (autoRotate)
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end
发布于 2012-11-01 06:05:44
如果你像我一样有一个标签栏,你唯一需要做的就是将下面的内容添加到你的委托.m文件中,
#import "AppDelegate.h"
//UITabBarController category to set the view rotations for ios 6
@implementation UITabBarController (Background)
-(BOOL)shouldAutorotate
{
//I don't want to support auto rotate, but you can return any value you want here
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
//I want to only support portrait mode
return UIInterfaceOrientationMaskPortrait;
}
@end
/////here starts the implementation of the app delegate which is gonna be whatever you currently have on your .m delegate
@implementation AppDelegate
// delegate methods and other stuff
@end
发布于 2012-09-26 05:33:54
我还有一个问题,那就是我需要一些视图来旋转,而另一些则不需要几个导航控制器。我通过告诉NavigationController查看视图控制器来做到这一点。这就是我所做的。
我创建了一个名为RootNavigationController的UINavigationController类,并将该类指定为storyboard中导航控制器的自定义类。在RootNavigationController.m中,我添加了以下方法;
- (BOOL)shouldAutorotate {
return [self.visibleViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.visibleViewController supportedInterfaceOrientations];
}
在每个视图控制器.m文件中,我还添加了以下方法。
- (BOOL)shouldAutorotate {
//return yes or no
}
- (NSUInteger)supportedInterfaceOrientations{
//return supported orientation masks
}
这样做可以让我在视图控制器中为每个视图设置方向。
不管怎样,…对我很管用
https://stackoverflow.com/questions/12522903
复制相似问题