长按时会显示两个操作表

发布于 2024-12-09 19:52:59 字数 864 浏览 4 评论 0原文

在我的 viewDidLoad 中,我有以下内容:

UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongpressGesture:)];
longpressGesture.minimumPressDuration = 1;
longpressGesture.allowableMovement = 5;
longpressGesture.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:longpressGesture];
[longpressGesture release];

我创建了以下内容:

-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Delete Record?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Yes",@"No",nil];
    [actionSheet showInView:self.view];
    [actionSheet release];
}

使用模拟器,当我长按时,会显示两个操作表,而不是一个。

关于为什么会这样的任何想法?
是模拟器的问题吗?

Inside my viewDidLoad, I have the following:

UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongpressGesture:)];
longpressGesture.minimumPressDuration = 1;
longpressGesture.allowableMovement = 5;
longpressGesture.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:longpressGesture];
[longpressGesture release];

I created the following:

-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Delete Record?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Yes",@"No",nil];
    [actionSheet showInView:self.view];
    [actionSheet release];
}

Using the simulator, when I long press, two action sheet shows up instead of the one.

Any ideas as to why this is so?
Is it a problem with the simulator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2024-12-16 19:52:59

不是模拟器的问题。

当手势经历不同的状态(开始、结束等)时,手势处理程序会被多次调用。

您需要在处理程序方法中检查手势的 state

-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
    if (sender.state == UIGestureRecognizerStateBegan)
    {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] init...
        [actionSheet showInView:self.view];
        [actionSheet release];
    }
}

It's not a problem with the simulator.

The gesture handler is called multiple times as the gesture goes through different states (began, ended, etc).

You need to check the gesture's state in the handler method:

-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
    if (sender.state == UIGestureRecognizerStateBegan)
    {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] init...
        [actionSheet showInView:self.view];
        [actionSheet release];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文