我有一個故事板,其中大部分視圖應該是縱向模式,但一個應該處於橫向模式。我減少了大量的搜索,但一直保持一個小小的空白。Autolayout IOS 7故事板強制橫向或縱向
我當前實現,其不完全似乎在工作,我希望由我從這個網站拼湊下面的代碼位:
我做了一個RotationalViewController從延伸UINavigationController的
#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
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
UIInterfaceOrientation ret = [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
return ret;
}
@end
然後我做了一個PortraitViewController
#import "PortraitViewController.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.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
和LandscapeViewController
#import "LandscapeViewController.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.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
@end
我有一些改變的設置,但無濟於事發揮各地。我的一般攻擊計劃是讓特定的視圖控制器從LandscapeViewController或PortraitViewController繼承,如果我想鎖定它們到一個特定的方向。
似乎縱向視圖工作(我可以將控制器鎖定到縱向視圖),但我似乎無法加載我的1橫向視圖,並讓它a)自動旋轉以加載景觀,或b)旋轉到風景在所有。
任何建議將不勝感激。
也許看看http://stackoverflow.com/questions/18957785/force-controllers-to-change-their-orientation-in-either-portrait-or-landscape?rq=1 – jackslash
這工作(有點) 。我想我可以調整它不會崩潰。謝謝 – Jeef
也許花一秒鐘的時間回答你自己的問題,爲你的社區的利益:) – jackslash