UIButton的停止滚动的UIScrollView斯威夫特

UIButton的停止滚动的UIScrollView斯威夫特

本文介绍了UIButton的停止滚动的UIScrollView斯威夫特的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的UIScrollView的区域,除了完美的滚动时按钮中的一个用户presses:

My UIScrollView area is scrolling perfectly except when the user presses on one of the buttons:

var button:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
button.frame = CGRectMake(0,0,self.width, self.menuHeight)
button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
button.tag = Int(itemNo)
scrollView.addSubview(button)

和buttonClicked code:

and the buttonClicked code:

func buttonClicked(sender:UIButton)
{
    var tag = sender.tag
    println(tag)
}

看来这TouchUpInside方法保持控制,即使当用户移动他的取景器从按钮离开。是什么让我的UIScrollView区滚动可靠的最佳方式?

It seems that the TouchUpInside method keeps control even when the user moves his finder away from the button. What is the best way of getting my UIScrollView area to scroll reliably?

推荐答案

尝试设置的 delaysContentTouches 属性的UIScrollView NO

此外,您还可以设置 canCancelContentTouches 属性。 (这是默认,但以防万一。)

Also, you can set canCancelContentTouches property to YES. (It's YES by default, but just in case.)



<一href=\"https://developer.apple.com/library/$p$prelease/iOS/documentation/UIKit/Reference/UIScrollView_Class/index.html#//apple_ref/occ/instp/UIScrollView/delaysContentTouches\"相对=nofollow>参考(从文档):


  • canCancelContentTouches :控制在内容视图触摸是否总是导致跟踪一个布尔值

  • canCancelContentTouches : A Boolean value that controls whether touches in the content view always lead to tracking.

delaysContentTouches :一个布尔值,确定滚动视图是否延迟向下触摸手势的处理

delaysContentTouches : A Boolean value that determines whether the scroll view delays the handling of touch-down gestures.

这篇关于UIButton的停止滚动的UIScrollView斯威夫特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:39