![](/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.