我在 UIScrollView
里面有 UIImageView
所以我可以允许缩放,缩放工作但它不会使 UIImageView
居中并最终切断图像的底部并在顶部留下黑色空间 .
这就是我所拥有的:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
scroller.bouncesZoom = YES;
scroller.clipsToBounds = YES;
float scale = image.size.width/320;
UIImage *scaled = [UIImage imageWithCGImage:[image CGImage] scale:scale orientation:UIImageOrientationUp];
imageView = [[UIImageView alloc] initWithImage:scaled];
imageView.userInteractionEnabled = YES;
[imageView setCenter:CGPointMake(160,240)];
[scroller addSubview:imageView];
scroller.contentSize = [imageView frame].size;
scroller.maximumZoomScale = 4.0;
scroller.minimumZoomScale = 1.0;
scroller.zoomScale = 1.0;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
有什么建议?
3 回答
我认为this就是你想要的 .
如果不需要分页,则禁用分页,它可以正常工作
scrollview.pagingEnabled = NO;
下面是我在我的应用程序中使用的代码(改编自WWDC示例)也许你可以从中获取一些东西:)