我目前正在使用沒有在界面構建器中設計的任何界面的customViewController
。只是你知道,我的目標是實現一個帶有容器行爲的layerViewController。面向風景的設備中的縱向視圖
一切都很順利,我包含的viewControllers行爲正確,但只有一件事:我希望所有這些僅在橫向模式下打印。
所以在我的init()方法以編程設定的我的customViewController
這樣的框架:
self.view.frame = [UIScreen mainScreen].applicationFrame;
,並告訴它:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
在這一點上似乎一切都很好,但有結果:
雖然設備理解只允許處於橫向模式,但它肯定給了我一個肖像的視圖。 (如果我刪除了supportedInterfaceOrientations
方法,視圖只需以縱向模式顯示)。
這是爲什麼發生?
編輯
我也嘗試添加類似下面的程序集的約束:
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
NSLayoutConstraint *botConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bottomLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
NSLayoutConstraint *leadingConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view.superview attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0];
NSLayoutConstraint *trailingConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view.superview attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0];
[self.view addConstraints:@[topConstraint, botConstraint, leadingConstraint, trailingConstraint]];
但沒有更滿意的結果:(
EDIT 2
我試圖玩myViewController.view.frame
和myViewController.view.bounds
但沒有什麼幫助,我的框架從來沒有設置到正確的風景之一。我有點不知所措......
張貼編輯,沒有工作。 – shinyuX