我有一个故事板,其中大部分视图应该是纵向模式,但一个应该处于横向模式。我减少了大量的搜索,但一直保持一个小小的空白。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