UIScrollView 中的 iPhone UIImageView 未缩放到中心
我在 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;
}
什么建议吗?
I have a UIImageView
inside a UIScrollView
so I can allow zooming, the zooming works but it doesn't keep the UIImageView
centered and ends up cutting off the bottom of the image and leaves black space on top.
This is what I have:
- (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;
}
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不需要分页,则禁用分页,它可以正常工作
scrollview.pagingEnabled = NO;
If pagination is not needed then disable pagination it works fine
scrollview.pagingEnabled = NO;
下面是我在应用程序中使用的代码(改编自 WWDC 示例)也许您可以从中获取一些东西:)
Below is the code I've used in my app (adapted from the WWDC sample) Maybe you can take something out of it :)