使用Xcode 4.2/iOS5.0
我有一个viewController和一个关联的viewController.xib.viewController被设置为.xib的文件所有者.它是从一个调用UINavigationController.
当设备旋转纵向/横向时,我正在尝试一些手动布局
据我所知UIView,覆盖的方法是
- (void)layoutSubviews;
Run Code Online (Sandbox Code Playgroud)
这是您进行布局的地方
但是 - 就像drawRect- 你不直接调用它,iOS适当时调用它
而是你打电话给setNeedsLayout......
所以我在ViewController中有这个
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)
fromInterfaceOrientation {
[[self view] setNeedsLayout];
}
Run Code Online (Sandbox Code Playgroud)
在同一个ViewController中,我有这个
- (void)layoutSubviews {
//.manual override of automatic layout on rotation
NSLog(@"layoutSubviews");
}
Run Code Online (Sandbox Code Playgroud)
然而layoutSubviews,没有被调用,我不明白为什么.
这是一个线索...如果我layoutSubviews直接打电话给[self layoutSubviews]
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)
fromInterfaceOrientation {
[self layoutSubviews];
}
Run Code Online (Sandbox Code Playgroud)
它会触发
但是如果我把它称为[[self view] layoutSubviews]它不是
那么看起来视图和它的控制器没有正确连线?