ios - Receive user input from UISwipeGestureRecognizer and UIScrollView -
i trying create uiscrollview performs action on scrollviewwillbegindragging , recognizes left , right swipes using uiswipegesturerecognizer. when use scrollviewwillbegindragging function, desired result on left swipe function cannot tell whether performing right or left swipe. if set detailscrollview.userinteractionenabled = false, gesturerecognizer performs correctly view no longer scrolls. here code:
override func viewdidload() { super.viewdidload() var leftswipe = uiswipegesturerecognizer(target: self, action: selector("handleswipes:")) var rightswipe = uiswipegesturerecognizer(target: self, action: selector("handleswipes:")) leftswipe.direction = .left rightswipe.direction = .right view.addgesturerecognizer(leftswipe) view.addgesturerecognizer(rightswipe) } func gesturerecognizer(uigesturerecognizer, shouldrecognizesimultaneouslywithgesturerecognizer:uigesturerecognizer) -> bool { return true } func scrollviewwillbegindragging(scrollview: uiscrollview) { if (counter < buttons.count) { serialselected(buttons[counter]) counter += 1 } } func handleswipes(sender:uiswipegesturerecognizer) { if (sender.direction == .left) { println("swipe left") var labelposition = cgpointmake(self.contentview.frame.origin.x - 50.0, self.contentview.frame.origin.y); contentview.frame = cgrectmake( labelposition.x , labelposition.y , self.contentview.frame.size.width, self.contentview.frame.size.height) } if (sender.direction == .right) { println("swipe right") var labelposition = cgpointmake(self.contentview.frame.origin.x + 50.0, self.contentview.frame.origin.y); contentview.frame = cgrectmake( labelposition.x , labelposition.y , self.contentview.frame.size.width, self.contentview.frame.size.height) } }
according source code, shouldrecognizesimultaneouslywithgesturerecognizer:uigesturerecognizer
never invoked.
// make delegate class yourclass: parentclass, uigesturerecognizerdelegate // reference delegate leftswipe.delegate = self rightswipe.delegate = self
Comments
Post a Comment