Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add swipe gesture to segmented control?

I have an ImageView added to UIView. Tapping on the image take to Segmented Control which is also part of same UIView. I am trying to add swipe gestures to this segmented control.

Tried following.

override func viewDidLoad() {
    super.viewDidLoad()

    let rightSwipe = UISwipeGestureRecognizer(target: SegmentCotroller, action: Selector("swiped:"))
    rightSwipe.direction = .Right
    self.SegmentCotroller.addGestureRecognizer(rightSwipe)
}

func swiped(sender:UIGestureRecognizer){
    print("Swiped.....!")
}

Code never reaches to swiped method when swiping right.

Any help is appreciated! Thanks

like image 616
user360 Avatar asked Dec 27 '25 23:12

user360


1 Answers

You need to se the swipe gestures target to self

let rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("swiped:"))
rightSwipe.direction = .Right
self.segmentController.addGestureRecognizer(rightSwipe)

The target sets where the action will be executed so you want it pointing at wherever you have the action implemented.

like image 173
Moriya Avatar answered Dec 30 '25 15:12

Moriya