按钮 touchDown 事件和 CPBPressureTouchGestureRecognizer
我的代码:
-(void)viewDidLoad {
[super viewDidLoad];
CPBPressureTouchGestureRecognizer* recognizer = [[CPBPressureTouchGestureRecognizer alloc] initWithTarget:self action:@selector(A_button:)];
[A_button addGestureRecognizer: recognizer];
[recognizer release];
[P2_button addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];
[P2_button addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
}
- (void) A_button: (CPBPressureTouchGestureRecognizer*) recognizer {
[self.presLabel setText:[NSString stringWithFormat:@"%f",recognizer.pressure]];
}
最后
-(IBAction)touchUp :(id)sender{
[myTimer invalidate];
myTimer = nil;
NSLog(@"up");
}
-(IBAction)touchDown :(id)sender{
myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(A_button:)
userInfo:nil
repeats:YES];
}
但不起作用,如果在计时器选择器中我写 @selector(A_button) 什么都不做,如果我写 @selector(A_button:) 返回错误:
2012-02-22 22:38:24.837 TestPres[19686:707] -[__NSCFTimer 压力]:无法识别的选择器发送到实例 0x143570 2012-02-22 22:38:24.847 TestPres[19686:707] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFTimer 压力]:无法识别的选择器发送到实例 0x143570”
问题出在哪里?当我按下m按钮时,如何才能显示0.1秒的压力值?
谢谢
my code:
-(void)viewDidLoad {
[super viewDidLoad];
CPBPressureTouchGestureRecognizer* recognizer = [[CPBPressureTouchGestureRecognizer alloc] initWithTarget:self action:@selector(A_button:)];
[A_button addGestureRecognizer: recognizer];
[recognizer release];
[P2_button addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];
[P2_button addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
}
- (void) A_button: (CPBPressureTouchGestureRecognizer*) recognizer {
[self.presLabel setText:[NSString stringWithFormat:@"%f",recognizer.pressure]];
}
and finally
-(IBAction)touchUp :(id)sender{
[myTimer invalidate];
myTimer = nil;
NSLog(@"up");
}
-(IBAction)touchDown :(id)sender{
myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(A_button:)
userInfo:nil
repeats:YES];
}
but don't work, if in timer selector i whrite @selector(A_button) do nothing, and if i whrite @selector(A_button:) return error:
2012-02-22 22:38:24.837 TestPres[19686:707] -[__NSCFTimer pressure]: unrecognized selector sent to instance 0x143570
2012-02-22 22:38:24.847 TestPres[19686:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer pressure]: unrecognized selector sent to instance 0x143570'
Where is the problem? How can display pressure value even 0.1 second when i touchDown m button?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
A_button:
方法需要将CPBPressureTouchGestureRecognizer
作为参数传入。当计时器触发时,它会调用该方法,但会传递NSTimer
对象。此外,压力手势识别器的工作方式与点击手势识别器非常相似。即使您保留对它的引用,它也不会持续监控所施加的压力。它仅是识别水龙头时的近似压力。
Your
A_button:
method is expecting aCPBPressureTouchGestureRecognizer
to be passed in as an argument. When your timer fires, it calls that method but passes theNSTimer
object instead.Also, the way the pressure gesture recognizer works is much like that of a tap gesture recognizer. Even if you kept a reference to it, it does not continuously monitor the pressure applied. It only approximates the pressure when the tap is recognized.