我在iOS 7和8上工作的應用程序在iOS9上有一些小問題,其中一個是單個視圖控制器得到錯誤的高度。UIViewController在初始加載時錯誤的高度
以下代碼:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self layoutViews];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self layoutViews];
}
- (void)layoutViews {
NSLog(@"Size-> %@", NSStringFromCGRect(self.view.frame));
}
產生如下誤輸出:
2015-11-06 22:42:31.737 app[62442:1136052] Size-> {{0, 0}, {375, 667}}
2015-11-06 22:42:33.318 app[62442:1136052] Size-> {{0, 32}, {667, 343}}
2015-11-06 22:42:34.885 app[62442:1136052] Size-> {{0, 64}, {375, 603}}
2015-11-06 22:45:18.063 app[62442:1136052] Size-> {{0, 32}, {667, 343}}
當I:
- 打開VC在肖像
- 旋轉到橫向
- 轉回肖像
- 轉回景觀
看來,VC的初始負載提供self.frame.size
下錯了尺寸,而所有後續的旋轉是正確的。 603
的高度是正確的,但您可以看到在兩次旋轉後,它在667
處仍然不正確。
我認爲與導航控制器欄有關可能會打破它。我在viewDidLoad
方法的代碼很簡單:
- (void)viewDidLoad {
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
[super viewDidLoad];
}
其中iOS上的正常工作8
更新 通過將呼叫固定這viewDidAppear
:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self layoutViews];
[activitiesTable flashScrollIndicators];
}
你已經啓用了狀態欄? –
是的,我總是有狀態欄。 –