I have my view set up in viewDidLoad
. All the different frames and such of the subviews have been defined relative to self.view
. Therefore it doesn't matter what size self.view
is the subviews will always shrink or expand to fit (as it were).
So when I rotate my device I want the view to rotate (easy enough with shouldAutoRotateToInterfaceOrientation:...
) but the subviews stay the same shape.
Calling [self viewDidLoad];
makes all the elements fit, but puts a new layer on top of the previous layout (which is obvious... but i'm just saying to explain what I mean).
Is there any way to refresh the frames of the subviews or something? I don't know what other people do to be honest. Am I going to have to put ALL of my views into the .h file as properties and do everything manually on didRotate...
?
Open your device's Settings app. . Select Accessibility. Select Auto-rotate screen.
Cause of Android Screen Not Rotating Any of the below issues can prevent your screen to rotate properly when you turn your phone. Auto rotate option is turned off or not working. The screen you're using isn't set to auto-rotate. Recent apps are interfering with auto-rotate.
You have three options:
If autoresizing masks are good enough to position your views, assign the correct autoresizing mask to each subview when you create them.
If autoresizing masks are not sufficient, override willAnimateRotationToInterfaceOrientation:duration:
and reposition your subviews in that method. I would create a custom method that takes the orientation as a parameter and is responsible for laying out all subviews. You can then call this method from willAnimateRotationToInterfaceOrientation:duration:
and from viewDidLoad
.
You could also create a custom UIView
subclass and make your view controller's view an instance of this class. Then override layoutSubviews
to position all subviews depending on the view's size. This approach implies that your custom view manages its subviews instead of the view controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With