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