小编Rya*_*Dao的帖子

iOS:如何获得长按手势的持续时间?

我正在开发一种游戏,通过长按对象本身来设置游戏对象的属性.属性的值由长按手势的持续时间确定.我正在使用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)

在这种情况下,如何获得长按手势的持续时间?

uigesturerecognizer ios

17
推荐指数
3
解决办法
3万
查看次数

iOS:未识别子视图的手势

我有一个UIScrollView作为我的根视图,一个UIImageView(让我们称之为父视图)作为根视图的子视图.然后我添加另一个UIImageView(lat的称之为子视图)作为父视图的子视图.子视图不包含在父视图的边界中.这是我的视图布局的直观表示.

................................
.       root view              .
.                  .........   .
.  ..............  . child .   .
.  .parent view .  . view  .   .
.  ..............  .........   .
.                              .
................................
Run Code Online (Sandbox Code Playgroud)

现在,当我向子视图添加UIPanGestureRecognizer时,无法识别手势.我检查了userInteractionEnabled和所有内容.当我将子视图设置为根视图的子视图时,可以正确识别手势.有谁知道是什么原因引起这个问题?

iphone uiview ipad uigesturerecognizer ios

2
推荐指数
1
解决办法
3475
查看次数

标签 统计

ios ×2

uigesturerecognizer ×2

ipad ×1

iphone ×1

uiview ×1