正如这个问题的标题所说,我需要创建一个视图,当点击或按住它时它需要有动作。这意味着我必须添加UITapGestureRecognizer
和UILongPressGestureRecognizer
. 我已经试过了。它以某种方式将我重定向到我需要去的屏幕,但它影响了它的后退按钮。从某种意义上说,受其影响,它会回到默认文本“项目”,并且它无法执行分配给它的操作。
问问题
600 次
2 回答
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
希望这会帮助你。
于 2013-11-07T06:24:38.060 回答
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];
于 2013-11-07T06:15:07.793 回答