【问题标题】:touchesBegan and touchesEnded not called on a UIButtontouchesBegan 和 touchesEnded 未在 UIButton 上调用
【发布时间】:2016-04-16 11:05:05
【问题描述】:

当我触摸UIButton 时,不会调用touchesBegantouchesMovedtouchesEnded 方法。我想在发生连续触摸时执行一个事件,并在触摸结束时取消该事件。

【问题讨论】:

  • 检查 userInteractionEnabled 在按钮及其所有超级视图上设置为 true。对于大多数UIViews,默认情况下为 true,但也有一些例外。
  • 对于 uibutton 这不是调用
  • 你设置的是delegate吗?

标签: ios uibutton uiresponder


【解决方案1】:

您可以使用 UIButton 控件事件跟踪 UIButton 触摸开始和触摸结束。

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.button addTarget:self action:@selector(touchStarted:) forControlEvents:UIControlEventTouchDown];
    [self.button addTarget:self action:@selector(touchEnded:) forControlEvents:UIControlEventTouchUpInside];
    [self.button addTarget:self action:@selector(touchEnded:) forControlEvents:UIControlEventTouchUpOutside];
}


- (void)touchStarted:(id)sender {
    NSLog(@"Touch started");
}

- (void)touchEnded:(id)sender {
    NSLog(@"Touch ended");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    相关资源
    最近更新 更多