layoutsubviews only called once despite any device rotation

人走茶凉 提交于 2019-12-04 17:36:19

Did you try setting the autoresizingMask on the UIView? For example like below:

someView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

From the UIView documentation:

'When a view’s bounds change, that view automatically resizes its subviews according to each subview’s autoresizing mask'

If you set the autoresizingMask to something other than None it should mean that the layoutSubviews method is always called when the views bounds change.

I'm not sure if it's exactly the same but i ran into a similar problem. I was using a UISplitViewContoller (template from Xcode) and adding a subview into the DetailViewController. The layoutSubviews methods was not getting called on rotation because it was a subview of the main UIView in the ViewController. So i added this to the DetailsViewController to get it to work (detailView is my subview):

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    if (detailView != nil) [detailView layoutSubviews];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!