marketplacer / paged-scroll-view-with-images

iOS UI control for showing images in a paged scroll view
MIT License
4 stars 5 forks source link

Add addGestureRecognizer in code #2

Closed leandrodavimg closed 9 years ago

leandrodavimg commented 9 years ago

Hello I'm using his great code, how can I add tap in scrollview

The code below works if it is equal to two ()

@IBOutlet weak var scrollView: UIScrollView! @IBOutlet weak var pageControl: UIPageControl! @IBOutlet var images: YiiPagedImages!

let TapRecognizer = UITapGestureRecognizer(target: self, action: "someAction:") TapRecognizer.numberOfTapsRequired = 2 //(must be 1) TapRecognizer.numberOfTouchesRequired = 1 scrollView.userInteractionEnabled = true scrollView.addGestureRecognizer(doubleTapRecognizer)

evgenyneu commented 9 years ago

Hi, hmm, I do not know why it is not working with a single tap. (I assume that is what you are asking).

You can implement it this way:

The YiiPagedImages object has a delegate property. That delegate has a tegPagedImagesCellViewDelegate_onImageTapped method that is called when an image in the scroll view is tapped.

If it does not work for you, there is an alternative I wrote recently: https://github.com/evgenyneu/Auk. It will allow you to add a custom gesture recognizer to your scroll view like this:

func setupTap() {
    let tapGesture = UITapGestureRecognizer(target: self, action: "respondToTap:")
    scrollView.addGestureRecognizer(tapGesture)
}

func respondToTap(gesture: UITapGestureRecognizer) {
    print("Tapped page \(scrollView.auk.currentPageIndex)")
}
leandrodavimg commented 9 years ago

Thanks, with your help managed to solve