正如这个问题的标题所说,我需要创建一个视图,当需要点击或按住它时需要采取行动。这意味着我必须添加UITapGestureRecognizer
和UILongPressGestureRecognizer
。我已经尝试过了。它以某种方式将我重定向到我需要去的屏幕,但它影响了它的后退按钮。受其意义影响,它会返回默认文本“Item”,并且无法执行指定的操作。
答案 0 :(得分:0)
是的,您可以在一个视图中添加这两个手势。请参阅以下代码
UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTap:)];
singleTapRecognizer.numberOfTapsRequired = 1;
singleTapRecognizer.delegate = self;
[self.view addGestureRecognizer:singleTapRecognizer];
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(didLongPress:)];
[longPressRecognizer setDelegate:self];
longPressRecognizer.allowableMovement = 1.0f;
longPressRecognizer.minimumPressDuration = 2.0;
[self.view addGestureRecognizer:longPressRecognizer];
答案 1 :(得分:0)
正如我在评论中提到的,你可以这样做,这里有一些代码可以帮助你。
UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
recognizer.delegate = self;
[view addGestureRecognizer:recognizer];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 2.0;
[view addGestureRecognizer:longPress];
以下是一些链接,以便您更好地理解: - https://developer.apple.com/library/ios/documentation/uikit/reference/UILongPressGestureRecognizer_Class/Reference/Reference.html
希望这会帮助你。