我正在开发一种游戏,通过长按对象本身来设置游戏对象的属性.属性的值由长按手势的持续时间确定.我正在使用UILongPressGestureRecognizer来实现这个目的,所以它是这样的:
[gameObjectView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handle:)]];
Run Code Online (Sandbox Code Playgroud)
然后是处理函数
- (void)handle:(UILongPressGestureRecognizer)gesture {
if (gesture.state == UIGestureRecognizerStateEnded) {
// Get the duration of the gesture and calculate the value for the attribute
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如何获得长按手势的持续时间?
我有一个UIScrollView作为我的根视图,一个UIImageView(让我们称之为父视图)作为根视图的子视图.然后我添加另一个UIImageView(lat的称之为子视图)作为父视图的子视图.子视图不包含在父视图的边界中.这是我的视图布局的直观表示.
................................
. root view .
. ......... .
. .............. . child . .
. .parent view . . view . .
. .............. ......... .
. .
................................
Run Code Online (Sandbox Code Playgroud)
现在,当我向子视图添加UIPanGestureRecognizer时,无法识别手势.我检查了userInteractionEnabled和所有内容.当我将子视图设置为根视图的子视图时,可以正确识别手势.有谁知道是什么原因引起这个问题?