设置scrollView内容的尺寸(滚动的范围) self.scrollView.contentSize = CGSizeMake(892, 480); self.scrollView.contentSize = self.minionView.image.size; self.scrollView.contentSize = self.minionView.frame.size; // 总体内容的范围(滚动范围) // <#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#> //外边距(用于穿透效果等) self.scrollView.contentInset = UIEdgeInsetsMake(10, 20, 40, 80);
- (IBAction)scroll { [UIView animateWithDuration:1.0 animations:^{ self.scrollView.contentOffset = CGPointMake(100, 0); }]; // CGPoint offset = CGPointMake(-100, -100); CGPoint offset = self.scrollView.contentOffset; offset.x += 10; offset.y += 10; [self.scrollView setContentOffset:offset animated:YES];}
- (void)viewDidLoad{ [super viewDidLoad]; // 设置内容尺寸// CGFloat contentH = self.lastBtn.frame.origin.y + self.lastBtn.frame.size.height+ 10; // 10是底部的间距 CGFloat contentH = CGRectGetMaxY(self.lastBtn.frame) + 10; self.scrollView.contentSize = CGSizeMake(0, contentH); // 增加额外的滚动区域(在顶部增加64的区域,在底部增加44的区域) self.scrollView.contentInset = UIEdgeInsetsMake(64, 0, 44, 0); // 设置一开始的滚动位置(往下滚动64) self.scrollView.contentOffset = CGPointMake(0, -64);}