This is perplexing to me. I want to change the frame of a UIScrollView upon orientation change:
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. Note that the subviews are all moved 156 pixels to the left, even though all I did was change the width of the parent scroll view (256 px smaller 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 do I prevent this?