我创建了一个按钮,并添加了一个长按手势,它在模拟器,iOS 6及以下设备上完美运行,而在iOS 7设备上它有时无法调用..
以下是生成按钮和手势识别器的代码
_gesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(myButtonLongPressed:)];
_gesture.minimumPressDuration = 0;
_gesture.numberOfTouchesRequired = 1;
CGRect rect = textView.frame;
tapToRecordBtn = [[UIButton alloc]initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width-5, rect.size.height)];
tapToRecordBtn.tag = 23;
[tapToRecordBtn setUserInteractionEnabled:YES];
[tapToRecordBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[tapToRecordBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
[tapToRecordBtn setTitle:@"Hold to Talk" forState:UIControlStateNormal];
[tapToRecordBtn setBackgroundImage:[UIImage imageNamed:@"talk-button.png"] forState:UIControlStateNormal];
[tapToRecordBtn addGestureRecognizer:_gesture];
[containerView addSubview:tapToRecordBtn];
这是手势调用的方法..
-(void) myButtonLongPressed:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan)
{
NSLog(@"gesture Began");
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
NSLog(@"gesture changed");
}
else if (gesture.state == UIGestureRecognizerStateEnded)
{
NSLog(@"gesture End");
}
}
这对我来说真是一个很大的麻烦...