这似乎是一个奇怪的问题.我在一个tableView中的迭代tableViewCell中有一个UIButton,它放在一个常规的ViewController中.出于某种原因,它只是长按时看起来被点击(从其默认蓝色突出显示为浅蓝色,然后再返回蓝色).它会在常规点击时执行我为其指定的任何操作(仅使用普通的旧打印语句启动),但只是看起来没有点击.有谁知道如何解决这个问题?
按钮处于正常状态:
按钮处于正常状态:
点击后按钮:
长按后按钮(抱歉,不得不用手机拍照)
解决方法
这是正常行为.这是由于UIScrollView的delaysContentTouches属性.根据Apple的
docs:
If the value of this property is YES,the scroll view delays handling
the touch-down gesture until it can determine if scrolling is the
intent. If the value is NO,the scroll view immediately calls
touchesShouldBegin:withEvent:inContentView:.
编辑:
This answer给出了以下解决方案.我测试过它确实有效.然而,由于它正在进行施法魔术,我不建议你实际执行此操作,因为当Apple决定在幕后更改其视图层次时,它将不可避免地中断.
tableView.delaysContentTouches = false for case let x as UIScrollView in tableView.subviews { x.delaysContentTouches = false }
老答案:
This answer提供了一个解决方案,但它真的是一个黑客,可能会导致您的应用程序因使用私有类而被Apple拒绝.由于行为确实是一个功能,我建议你保持原样.