1:没有设置contentSize
2:scrollEnabled = NO
3:没有接收到触摸事件:userInteractionEnabled = NO
self.automaticallyAdjustsScrollViewInsets = NO;
//---导入代理
@interface RootViewController ()<UIScrollViewDelegate>
@end
@implementation RootViewController
//viewDidLoad只执行一次
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
//-创建滚动视图 当我们需要显示的内容超过一屏时,就需要用到滚动视图
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
[scrollView setBackgroundColor:[UIColor orangeColor]];
[self.view addSubview:scrollView];
//-Key:设置滚动区域(内容区域的大小)
scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame) * 4, CGRectGetHeight(self.view.frame));
//-为scrollview添加子视图
// NSArray *colorArr = [NSArray arrayWithObjects:[UIColor cyanColor], [UIColor greenColor], [UIColor redColor], [UIColor blueColor], nil];
NSArray *imageArr = [NSArray arrayWithObjects:[UIImage imageNamed: @"woman1.jpg"], [UIImage imageNamed: @"woman2.jpg"], [UIImage imageNamed: @"woman3.jpg"], [UIImage imageNamed:@"woman4.jpg"], nil];
for (int i = 0; i < 4; i++) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame)*i, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
label.text = [NSString stringWithFormat:@"这是志南的第%d夫人", i+1];
label.font = [UIFont systemFontOfSize:30];
label.textAlignment = NSTextAlignmentCenter;
// label.backgroundColor = colorArr[i];//
UIImageView *imageView = [[UIImageView alloc] initWithImage:imageArr[i