Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

ios - How to zoom a UIScrollView inside of a UICollectionViewCell?

I'm trying to add a UIScrollView inside of a UICollectionViewCell. The idea is that you can use pinch to zoom the UIScrollView (and with it, the image within), but the scrollview doesn't seem to handle any gesture. I'm guessing they are being caught by the UICollectionView.

I've set the delegate of the UIScrollView to be the UICollectionViewCell, but none of the delegate methods are being called.

EDIT: I've made a github repo with the code (simplified as much as I could). Even though it's just a few lines of code, I cannot see what I did wrong.

EDIT2: After the answer was found, I added the fixes to the above-mentioned repo, hope others find it helpful too :)

https://github.com/krummler/gallery-pinchzoom-example

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just made an implementation for SWIFT 3 on iOS 9.3+ and all i done was:

1. Place the image view inside a scrollview

storyboard example

2. Connect the scrollview delegate to collectionview cell class

3. Implement the code below on the collectionview subclass

class FullScreenImageTextDetailCollectionViewCell: UICollectionViewCell, UIScrollViewDelegate {

     @IBOutlet var scrollview: UIScrollView!
     @IBOutlet weak var backgroundImageView: UIImageView!

     override func awakeFromNib() {
         self.scrollview.minimumZoomScale = 0.5
         self.scrollview.maximumZoomScale = 3.5
         self.scrollview.delegate = self
     }

     func viewForZooming(in scrollView: UIScrollView) -> UIView? {
         return self.backgroundImageView
     }
}

No gesture recognizer adding or removing on the parent collectionview controller was necessary, worked like a charm!

Thanks for previous examples for reaching this!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...