手机上的按钮无响应

时间:2017-03-23 09:03:41

标签: ios objective-c

[_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;

请帮帮我......

2 个答案:

答案 0 :(得分:0)

如果这是在自定义按钮类中编写的代码,那么当您启动类对象(实际按钮)时,请确保设置以下属性,如下所示:

button.userInteractionEnabled = YES;

答案 1 :(得分:0)

请将UIImageview属性设置为UserInteraction enable = true

imgYouimage.userInteractionEnable = True;

它会起作用。