改变内容偏移
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset
显示contentsize中的某部分
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated; // scroll so rect is just visible (nearest edges). nothing if rect completely visible
注意:
1. 使用 - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 时, 需要注意,
在uiscrollview的委托中只有, 以下这个方法可以阻止减速, 并且更改内容偏移, 一就是setContentOffset这个方法
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
2. viewForZoomingInScrollView: 需要设置
minimumZoomScale
maximumZoomScale 才能够调用
uiscrollview缩放图片至少实现一下两个代理, 但能让缩放过程更加自然
//实现图片在缩放过程中居中//scrollView正在缩放- (void)scrollViewDidZoom:(UIScrollView *)scrollView{ CGFloat offsetX = (scrollView.bounds.size.width > scrollView.contentSize.width)?(scrollView.bounds.size.width - scrollView.contentSize.width)/2 : 0.0; CGFloat offsetY = (scrollView.bounds.size.height > scrollView.contentSize.height)?(scrollView.bounds.size.height - scrollView.contentSize.height)/2 : 0.0; UIView *v = [scrollView.subviews objectAtIndex:0]; v.center = CGPointMake(scrollView.contentSize.width/2 + offsetX,scrollView.contentSize.height/2 + offsetY);}#pragma mark - UIScrollViewDelegate- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ return _imageView;}