我正在尝试使用UIScrollView
和创建一个水平滚动UIImageView
。图像视图的宽度为 1280 像素(4 页),滚动视图的宽度为 320 像素。当我在没有自动布局模式的情况下使用此代码时,滚动工作正常:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.scrollView.scrollEnabled = YES;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.showsHorizontalScrollIndicator = NO;
CGRect imageFrame = self.helpImageView.frame;
NSLog(@"imageFrame w: %f",self.helpImageView.frame.size.width); //prints 1280.000000
[self.scrollView setContentSize:imageFrame.size];
NSLog(@"contentSize w: %f",self.scrollView.contentSize.width); //prints 1280.0000
NSLog(@"scrollFrame w: %f",self.scrollView.frame.size.width); //prints 320.00
}
但是,如果我想使用 Autolayout,此代码会返回相同的结果,但UIScrollView
不会滚动。为什么???我正在使用这些限制:
Bottom space to: ScrollView Equals:32.0
Leading space to: ScrollView
Trailing space to: ScrollView
Top Space To: SCrollView Equals:-20.0
Bottom Space To: View Equals:-12.0
Leading space to: View
Top Space To: View Equals:427.0
Trailing space to: View