[_imgviewBtn addTarget:self action:@selector(recordButtonTouchDown) forControlEvents:UIControlEventTouchDown];
[_imgviewBtn addTarget:self action:@selector(recordButtonTouchUpOutside) forControlEvents:UIControlEventTouchUpOutside];
[_imgviewBtn addTarget:self action:@selector(recordButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
[_imgviewBtn addTarget:self action:@selector(recordDragOutside) forControlEvents:UIControlEventTouchDragOutside];
[_imgviewBtn addTarget:self action:@selector(recordDragInside) forControlEvents:UIControlEventTouchDragInside];
[self addSubview:_imgviewBtn];
- (void)recordButtonTouchDown {
if (self.delegate && [self.delegate respondsToSelector:@selector(recordButtonTouchDown)]) {
[self.delegate recordButtonTouchDown];
}
}
- (void)recordButtonTouchUpInside {
if (self.delegate && [self.delegate respondsToSelector:@selector(recordButtonTouchUpInside)]) {
[self.delegate recordButtonTouchUpInside];
}
}
- (void)recordButtonTouchUpOutside {
if (self.delegate && [self.delegate respondsToSelector:@selector(recordButtonTouchUpOutside)]) {
[self.delegate recordButtonTouchUpOutside];
}
}
- (void)recordDragOutside {
if (self.delegate && [self.delegate respondsToSelector:@selector(recordDragOutside)]) {
[self.delegate recordDragOutside];
}
}
- (void)recordDragInside {
if (self.delegate && [self.delegate respondsToSelector:@selector(recordDragInside)]) {
[self.delegate recordDragInside];
}
}
如果我点击UIControlEventTouchDown
,请在离开时UIControlEventTouchUpInside
无响应。如果UIControlEventTouchUpOutside
离开,相同的非响应UIControlEventTouchDragOutside
,模拟器在手机上运行没问题就有问题,iOS10.1,Xcode8.1;
请帮帮我......
答案 0 :(得分:0)
如果这是在自定义按钮类中编写的代码,那么当您启动类对象(实际按钮)时,请确保设置以下属性,如下所示:
button.userInteractionEnabled = YES;
答案 1 :(得分:0)
请将UIImageview属性设置为UserInteraction enable = true
imgYouimage.userInteractionEnable = True;
它会起作用。