![](/img/trans.png)
[英]Setting titleTextAttriubutes of navigationBar crashes the app only on ios 7.1 device not simulator
[英]Autorotation only working in simulator not on device (IOS 7.1)
我尝试了这里发布的各种方法,以使用情节提要板在IOS7中正确设置自动旋转。 我“应该”执行的工作因为它在模拟器中可以很好地工作,但是当我将代码加载到设备(iPad或iPhone)上时,它不会旋转。
[更新:现在可以在iPad上旋转代码,但在Mini或iPhone上不能旋转代码?]
在模拟器(和IPAD)中:
在IPHONE / IPAD Mini上:
我不知道有什么区别。 如果有人有任何建议,那将是超级有帮助的,因为这会使我发疯。
我遵循的方法如下:
我遵循在某处提到的方法,并创建了一个名为RotationControlledViewController
的UINavigationController
的子类(下面的代码)。
然后,我使LandscapeViewController
和PortraitViewController
成为UIViewController
子类。 我想锁定到特定方向的View Controller从这些类继承,而不是从UIViewController
继承
(是的-我确实确保在设备上禁用了旋转锁)
RotationViewController
//
// RotationControlledViewController.m
// ASGAARD
//
// Created by Jeff Stein on 2/16/14.
// Copyright (c) 2014 Jeff Stein. All rights reserved.
//
#import "RotationControlledViewController.h"
@interface RotationControlledViewController ()
@end
@implementation RotationControlledViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
BOOL ret = [[self.viewControllers lastObject] shouldAutorotate];
// NSLog(@"--Auto Roatate Reported %d", ret);
return ret;
}
-(NSUInteger)supportedInterfaceOrientations
{
NSUInteger ret = [[self.viewControllers lastObject] supportedInterfaceOrientations];
// NSLog(@"--supportedInterfaceOrientations: %d", ret);
return ret;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
UIInterfaceOrientation ret = [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
// NSLog(@"--preferredInterfaceOrientationForPresentation: %ld",ret);
return ret;
}
@end
LandscapeViewController
//
// LandscapeViewController.m
// ASGAARD
//
// Created by Jeff Stein on 2/16/14.
// Copyright (c) 2014 Jeff Stein. All rights reserved.
//
#import "LandscapeViewController.h"
#import "objc/message.h"
@interface LandscapeViewController ()
@end
@implementation LandscapeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);
NSLog(@"Issuing a rotation message (hopefully");
}
-(void)viewDidAppear:(BOOL)animated {
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
@end
PortraitViewController
//
// PortraitViewController.m
// ASGAARD
//
// Created by Jeff Stein on 2/16/14.
// Copyright (c) 2014 Jeff Stein. All rights reserved.
//
#import "PortraitViewController.h"
#import "objc/message.h"
@interface PortraitViewController ()
@end
@implementation PortraitViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait);
}
- (void)viewDidAppear:(BOOL)animated {
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
@end
更新-其他异常:
在无法正常工作的IPAD Mini上,我处于横向并导航至“应”为人像的视图。 它启动一个警报,该警报是纵向对齐的,但视图本身是横向的。 查看比较:
我注意到屏幕截图是纵向显示的(警报也是如此)。 对我来说,这意味着迷你“以肖像”方式“思考”它,但是以某种方式不能正确更新视图控制器。
IPAD显然是正确的。
我在GitHUB上做了一个示例项目来演示该问题:
您似乎在这里遇到的情况与IOS7及更高版本有关。 从我所看到的,做您要寻找的唯一方法是使用模式搜索将第二个导航控制器实际添加到堆栈中。 或者,您可以尝试关闭自动版式。 我认为这些选项都不是您想听到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.