Zac*_*her 16 objective-c rotation uitabbarcontroller ios6
确认!我最终在iOS 5中解决了我的tabbar旋转问题,但是iOS 6和xcode似乎已经破坏了......这就是我所拥有的:
目标应用程序摘要包括:支持的界面方向 - Portraint,Landscape Left,Landscape Right
应用程序中的每个单一视图都有以下方法:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
在不属于选项卡栏的视图中,旋转被阻止.在标签栏的所有视图中(有5个),应用程序从不调用ShouldAutorotate,因此旋转.它确实看起来supportInterfaceOrientations在视图加载时被调用一次,但是当我在视图之间切换时它不会被调用,因为我得到了NSLog,但似乎忽略了MaskPortrait设置.
我必须在目标中启用横向,因为我有一个需要旋转的视频播放器视图(它确实如此,很好)
这是iOS 6中的tabbar错误吗?我是否需要以不同方式禁用视图的旋转?在ios 5中,shouldautorotatetointerfaceorientation运行良好
我已经有一段时间了
谢谢,扎克
小智 36
扎克,我遇到了同样的问题.这是因为你将viewController嵌入到TabBar控制器或UINavigationController中,并且这些方法的调用发生在那些方法中,而不是普通的View(在iOS6中更改).
我遇到了这个问题,因为我在我的所有模态视图中呈现了嵌入在UINavigationController中的viewController,这些视图具有导航到不同视图(注册过程,登录等).
我的简单修复是为UINavigationController创建一个包含这两种方法的CATEGORY.我无论如何都应该返回NO,因为我不希望我的模态视图旋转.你的修复可能很简单,试一试.希望能帮助到你.
我创建了一个类别并将其命名为autoRotate并选择了UINavigationController选项.M + H文件如下.
#import "UINavigationController+autoRotate.h"
@implementation UINavigationController (autoRotate)
-(BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
@end
Run Code Online (Sandbox Code Playgroud)
......和类别.h:
#import <UIKit/UIKit.h>
@interface UINavigationController (autoRotate)
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end
Run Code Online (Sandbox Code Playgroud)
Mon*_*ona 11
如果您有像我一样的标签栏,您唯一需要做的就是将以下内容添加到您的委托.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
Run Code Online (Sandbox Code Playgroud)
我还遇到了一个问题,我需要一些视图来旋转,而其他视图则不需要多个导航控制器.我通过告诉NavigationController查看视图控制器来做到这一点.这就是我做的.
我创建了一个名为RootNavigationController的UINavigationController类,并将该类指定为故事板中导航控制器的自定义类.在RootNavigationController.m中,我添加了以下方法;
- (BOOL)shouldAutorotate {
return [self.visibleViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.visibleViewController supportedInterfaceOrientations];
}
Run Code Online (Sandbox Code Playgroud)
在每个视图控制器.m文件中,我还添加了以下方法.
- (BOOL)shouldAutorotate {
//return yes or no
}
- (NSUInteger)supportedInterfaceOrientations{
//return supported orientation masks
}
Run Code Online (Sandbox Code Playgroud)
这样做允许我在视图控制器中为每个视图设置方向.
无论如何,为我工作......
小智 6
我的情况是:
所以我的工具:创建UITabBarController类和UINavigationCntroller类
的UITabBarController + autoRotate.h
@interface UITabBarController (autoRotate)
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end
Run Code Online (Sandbox Code Playgroud)
的UITabBarController + autoRotate.m
#import "UITabBarController+autoRotate.h"
@implementation UITabBarController (autoRotate)
- (BOOL)shouldAutorotate {
return [self.selectedViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.selectedViewController supportedInterfaceOrientations];
}
@end
Run Code Online (Sandbox Code Playgroud)
UINavigationController的+ autoRotate.h
@interface UINavigationController (autoRotate)
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end
Run Code Online (Sandbox Code Playgroud)
UINavigationController的+ autoRotate.m
@implementation UINavigationController (autoRotate)
- (BOOL)shouldAutorotate {
return [self.visibleViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.visibleViewController supportedInterfaceOrientations];
}
@end
Run Code Online (Sandbox Code Playgroud)
UIViewController1.m
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;;
}
Run Code Online (Sandbox Code Playgroud)
UIViewController2.m
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)
它就像一个魅力!
| 归档时间: |
|
| 查看次数: |
14264 次 |
| 最近记录: |