我想处理我的禁用按钮
self.closeButton.enabled = NO;
self.closeButtonDisabledRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeButtonDisablePressed)];
[self.closeButton addGestureRecognizer:self.closeButtonDisabledRecognizer];
但似乎它不起作用。有什么好办法吗?
答案 0 :(得分:0)
禁用太像是告诉SDK忽略你想要的触摸。我建议改为:
@property(assign, nonatomic) BOOL treatTheCloseButtonAsEnabled;
// replace the synthesized setter
- (void)setTreatTheCloseButtonAsEnabled:(BOOL)enabled {
self.closeButton.alpha = (enabled)? 1.0 : 0.5;
// or some other visible indication of the "disabled" state
}
- (IBAction)pressedCloseButton:(id)sender {
if (self.treatTheCloseButtonAsEnabled) {
// logic for a regular press
} else {
// logic for a disabled press
}
}
答案 1 :(得分:0)
也许你也可以在控制器中使用触摸事件。它会是这样的(我假设你的关闭按钮被添加到controller.view上):
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
touchPoint = [self.view convertPoint:touchPoint toView:_closeButton.superview];
//to determine wether user touch on you button
if (CGRectContainsPoint(_closeButton.frame, touchPoint) == NO) {
return;
}
//handle your touch on button here
}