【发布时间】:2015-03-14 12:36:02
【问题描述】:
在我的 swift ios 应用程序中。我使用下面的代码在我的屏幕上创建一个圆形 UIView。然后我向它添加一个 UILongPressGestureRecognizer ,将视图本身以及gestureRecognizer 保留在它们各自的数组中。每次用户触摸并按住此视图时,代码都会再次运行并创建另一个视图并向其中添加另一个 UILongPressGestureRecognizer。
let x = CGFloat(arc4random_uniform(UInt32(sW-w)))
let y = CGFloat(arc4random_uniform(UInt32(sH-h-10)))+15
circle.append(UIButton())
touch.append(UILongPressGestureRecognizer())
let l = circle.count-1
circle[l].frame = CGRect(x:x, y:y, width:70, height:70)
circle[l].backgroundColor = UIColor.redColor()
circle[l].layer.cornerRadius = w/2
circle[l].clipsToBounds = true
touch[l].addTarget(self, action: "touched:")
touch[l].minimumPressDuration = 0
touch[l].numberOfTouchesRequired = 1
touch[l].numberOfTapsRequired = 0
touch[l].allowableMovement = 0
touch[l].delegate = self
circle[l].addGestureRecognizer(touch[l])
self.view.addSubview(circle[l])
现在,当我运行应用程序时,我可以点击并按住圆形视图,它的状态会更改为 .Began,它还会触发最多 5 个视图的 .Changed 和 .Ended 状态。但是当添加第 6 个视图时,手势识别器无法在其上工作。
Apple 文档中没有关于同时工作的手势识别器的最大数量。还有什么可能导致这种行为?
【问题讨论】:
-
只是想更新对此问题感兴趣的每个人,经过大量研究,如here 所述,我发现 iPhone 仅限于 5 次同时触摸。
标签: ios xcode swift uigesturerecognizer