按钮 touchDown 事件和 CPBPressureTouchGestureRecognizer

发布于 2025-01-08 00:07:13 字数 1506 浏览 1 评论 0原文

我的代码:

-(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心奴独伤 2025-01-15 00:07:13

您的 A_button: 方法需要将 CPBPressureTouchGestureRecognizer 作为参数传入。当计时器触发时,它会调用该方法,但会传递 NSTimer 对象。

此外,压力手势识别器的工作方式与点击手势识别器非常相似。即使您保留对它的引用,它也不会持续监控所施加的压力。它仅是识别水龙头时的近似压力。

Your A_button: method is expecting a CPBPressureTouchGestureRecognizer to be passed in as an argument. When your timer fires, it calls that method but passes the NSTimer 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文