iphone - 按下按钮时

标签 iphone objective-c ios xcode ipad

我如何设置一个按钮(附有 IBAction 和 UIButton)以在按下按钮时继续运行 IBAction 或函数,持续运行一个函数直到按钮松开。

我应该附加一个值(value)改变的接收器吗?

简单的问题,但我找不到答案。

最佳答案

[myButton addTarget:self action:@selector(buttonIsDown) forControlEvents:UIControlEventTouchDown];
[myButton addTarget:self action:@selector(buttonWasReleased) forControlEvents:UIControlEventTouchUpInside];


- (void)buttonIsDown
{
     //myTimer should be declared in your header file so it can be used in both of these actions.
     NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(myRepeatingAction) userInfo:nil repeats:YES];
}

- (void)buttonWasReleased
{
     [myTimer invalidate];
     myTimer = nil;
}

关于iphone - 按下按钮时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11998361/

相关文章:

iPhone - SKProductsRequest 和 "message sent to deallocated instance"

iphone - 使用日文键盘时应用程序在 Lock 上崩溃

objective-c - 如何仅从核心数据中获取前 20 个对象

ios - 如何在 Table View Xcode 中提供 'real time' 更新

iphone - 如果应用程序终止,则删除的 NSHTTPCookie 返回

iphone - 如何从 GPS 坐标查找邮政编码?

objective-c - 单击 NSTextField 标签以模拟指向文件夹的超链接

objective-c - 如何从静态单元格表​​ View 中删除部分

ios - 无效的 Facebook token

ios - 使用 IOS 设备的蓝牙连接