一个电视机音量+按键的功能:
(1)每按一次其音量+1
(2)长按音量持续增加
此时我们就需要给这个按钮添加两种事件了:
UIButton *btnVoiceUp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnVoiceUp.frame = CGRectMake(40, 100, 60, 40);
[btnVoiceUp setBackgroundImage:[UIImage imageNamed:@"tv_voiceUp"] forState:UIControlStateNormal];
[btnVoiceUp addTarget:self action:@selector(BtnVoiceUpAction:) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *longPressGesUp = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressUp:)];
longPressGesUp.minimumPressDuration = 0.5;
[btnVoiceUp addGestureRecognizer:longPressGesUp];
//音量+长按事件
-(void)longPressUp:(UILongPressGestureRecognizer *)longGes{
//音量+长按事件逻辑
}