我的代码:
-(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 pressure]:无法识别的选择器发送到实例 0x143570 2012-02-22 22:38:24.847 TestPres[19686:707] *由于未捕获而终止应用程序异常“NSInvalidArgumentException”,原因:“-[__NSCFTimer 压力]:无法识别的选择器发送到实例 0x143570”
问题出在哪里?当我按下 m 按钮时,如何显示压力值甚至 0.1 秒?
谢谢