【发布时间】:2010-10-14 18:21:50
【问题描述】:
这让我很困惑。我想在方向改变时改变 UIScrollView 的框架:
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);
}
}
这是结果。请注意,子视图都向左移动了 156 像素,即使我所做的只是更改父滚动视图的宽度(纵向模式下小 256 像素):
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
为什么?以及如何防止这种情况发生?
【问题讨论】:
标签: iphone ipad uiscrollview positioning