1
我有一个滚动视图,里面有一些图像,我水平滚动。我想使用捏手势进行缩放。这是我正在使用的代码,但它不起作用。我似乎无法弄清楚我做错了什么。有什么建议吗?在ScrollView中缩放图像
let scrollView = UIScrollView(frame: CGRect(x: 0, y: 100, width: UIScreen.main.bounds.size.width , height: (UIScreen.main.bounds.size.height - 140))) var frame: CGRect = CGRect(x: 0, y: 0, width: 0, height: 0)
var subView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
getOfferImages()
swipeGesture()
setupView()
scrollView.delegate = self
scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 4.0
}
func configureScrollView(){
scrollView.backgroundColor = UIColor.black
scrollView.showsHorizontalScrollIndicator = false
scrollView.isUserInteractionEnabled = true
scrollView.clipsToBounds = true
scrollView.bouncesZoom = true
pageNumberlabel.text = "1 of \(offersImagesArray.count)"
self.view.addSubview(scrollView)
for index in 0..<images.count {
frame.origin.x = self.scrollView.frame.size.width * CGFloat(index)
frame.size = self.scrollView.frame.size
subView = UIImageView(frame: frame)
subView.tag = 1
subView.contentMode = .scaleToFill
subView.isUserInteractionEnabled = true
subView.sd_setImage(with: images[index], placeholderImage: UIImage(named:""), options: [.continueInBackground])
self.scrollView.addSubview(subView)
}
self.scrollView.isPagingEnabled = true
self.scrollView.contentSize = CGSize(width: (self.scrollView.frame.size.width * CGFloat(images.count)), height: self.scrollView.frame.size.height)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
// let image = self.view.findSubview(withTag: 1)
return self.subView
}
所以,我想这回你的形象,它会识别缩放手势,但它不不放大图像,它只是闪烁一点。 – Stephanie
@Stephanie请参阅编辑。 – MwcsMac
@Stephanie为你工作过吗?还是你仍然有问题? – MwcsMac