开发者

changing subviews when rotating on ios

开发者 https://www.devze.com 2023-02-27 05:34 出处:网络
I need a view controller(on ipad) to share two modes, one in portrait and one in landscape. Actually, I pretty much want to mimic the functionality of UISplitViewController, but I want to be able to u

I need a view controller(on ipad) to share two modes, one in portrait and one in landscape. Actually, I pretty much want to mimic the functionality of UISplitViewController, but I want to be able to use not as the top level view controller. HIG guidelines aside, I have a general problem that I think anyone who is switching views between orientations will run into.

1) To provide for smooth transitions between views, I would like to call my view changes( and animations) inside willRotateToInterfaceOrientation:duration instead of didRotateToInterfaceOrientati开发者_开发知识库on method. The problem is, at this stage, the view frame and bounds have not yet changed to their new ones, so you end up having to set the frame manually, like:

subview.frame = CGRectMake(0,0,320,768);

instead of something nicer, maybe:

subview.frame = CGRectMake(0,0,320, self.view.frame.height);

2) Furthermore, even if you try such shenanigans, if the view autoresizes its subviews, you still get nowhere with it. If you disable the autoresizing of subviews, then stuff like this does not even work anymore:

subview.frame = self.view.frame; //because then you'd have to always specify the exact rect.

Does anyone have any insight to offer on this?

Thanks!


Try using willAnimateRotationToInterfaceOrientation:duration: instead.

Also, if you have your autoresizing masks set up correctly on the subviews, you shouldn't need to care whether the main view has been adjusted yet or not. Just size the subviews to fit appropriately inside the main view as it is sized now and it will just work.

If you don't (or can't) have your autoresizing masks set up correctly, you should then already have code to handle size changes in the main view's layoutSubviews method. So again, you shouldn't have to care much whether the main view has been resized yet or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消