It puzzles me. I want to change the UIScrollView frame when changing orientation:
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
self.myScrollView.frame = CGRectMake(40, 40, 984, 200);
for (UIView* view in [self.myScrollView subviews]){
NSLog(@"subview x: %f", view.frame.origin.x);
}
}
else{
self.myScrollView.frame = CGRectMake(40, 40, 728, 200);
for (UIView* view in [self.myScrollView subviews]){
NSLog(@"subview x portrait: %f", view.frame.origin.x);
}
}
Here are the results. Please note that all views move 156 pixels to the left, although all I did was change the width of the parent scroll (256 pixels less in portrait mode):
subview x: 0.000000
subview x: 128.000000
subview x: 256.000000
subview x: 384.000000
subview x portrait: -156.000000
subview x portrait: -28.000000
subview x portrait: 100.000000
subview x portrait: 228.000000
Why?? And how to prevent it?
source
share