[英]Zoom/Scroll through parts of image in a scrollview
I have an image which I divide into pages, such that each page shows a zoomed rectangle of the image. 我有一张图像,我将其分为几页,以便每一页都显示该图像的缩放矩形。 I think I should be able to do that with a UIImageView in a ScrollView, such that next page zooms the view to a given point.
我想我应该能够使用ScrollView中的UIImageView做到这一点,以便下一页将视图缩放到给定点。 However I can't seem to get it to work.
但是我似乎无法使其正常工作。
This is the code for loading the image and setting the zoom on the first part (ie the first page) into scrollview: 这是用于加载图像并将第一部分(即第一页)上的缩放比例设置为scrollview的代码:
scrollView.isPagingEnabled = true
scrollView.contentSize = CGSize(width: 1280, height: 1920)
scrollView.showsHorizontalScrollIndicator = false
scrollView.delegate = self as UIScrollViewDelegate
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame.origin.x = 0
scrollView.addSubview(imageView)
scrollView.zoom(toPoint: CGPoint(x:800,y:800), scale: 1, animated: false)
The image is obviously much larger than the size of the scrollview, which is 375/309. 该图像显然比滚动视图的大小(375/309)大得多。
I'm probably missing a lot here, or maybe there's a completely different way of achieving this. 我可能在这里错过了很多东西,或者也许有一种完全不同的方式来实现这一目标。
the zoom function is borrowed from https://gist.github.com/TimOliver/71be0a8048af4bd86ede . 缩放功能是从https://gist.github.com/TimOliver/71be0a8048af4bd86ede借用的。
Thanks, Z. 谢谢Z
It seems like you'll want to set the content offset rather than zooming to a point. 似乎您将要设置内容偏移而不是缩放到一个点。 Try:
尝试:
scrollView.contentOffset = CGPoint(x:800,y:800)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.