【发布时间】:2015-10-02 07:34:23
【问题描述】:
我正在尝试创建一个 UIScrollView,它在 scrollViewWillBeginDragging 上执行操作,并且还使用 UISwipeGestureRecognizer 识别左右滑动。当我使用 scrollViewWillBeginDragging 函数时,我在向左滑动时获得了所需的结果,但我的函数无法判断我是在执行向右还是向左滑动。如果我设置 detailScrollView.userInteractionEnabled = false,则gestureRecognizer 会正确执行,但视图不再滚动。这是我的代码:
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)
}
}
【问题讨论】:
标签: ios swift uiscrollview uigesturerecognizer