Cocoa touch 按住按钮
我是IOS开发的新手,有一点java和Arduino编程经验。我正在做一个简单的莫尔斯电码项目。如何跟踪iOS中按下按钮的时间?我是否需要有一个大的循环来不断地扫描被按下的按钮?您必须结合两个功能结果:Cocoa touch 按住按钮,cocoa-touch,ios6,Cocoa Touch,Ios6,我是IOS开发的新手,有一点java和Arduino编程经验。我正在做一个简单的莫尔斯电码项目。如何跟踪iOS中按下按钮的时间?我是否需要有一个大的循环来不断地扫描被按下的按钮?您必须结合两个功能结果: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 这就是开始时间 及 如果触碰内部,则获得“结束时间”并计算持续时间。您必须组合两个功能结果: - (void)touchesBegan:(NSSet *)touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
这就是开始时间
及
如果触碰内部,则获得“结束时间”并计算持续时间。您必须组合两个功能结果:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
这就是开始时间
及
如果触地得分超过你得到“结束时间”并计算持续时间。我会这样做: 向类中添加属性以存储最近一次触地的日期。最好是在
.m
-文件中的类扩展名中
@interface YourViewController ()
@property (nonatomic, strong) NSDate *buttonTouchDownDate;
@end
以编程方式或使用interface builder将按钮连接到触控按钮
和触控按钮内部
控制事件。这是非常详细的描述
然后存储按下按钮的日期。抬起手指时,计算存储日期与现在之间的时间间隔
- (IBAction)buttonDidTouchDown:(id)sender
{
self.buttonTouchDownDate = [NSDate date];
}
- (IBAction)buttonDidTouchUp:(id)sender
{
// Will return a negative value, so we use the ABS-macro.
NSTimeInterval timeInterval = ABS([self.buttonTouchDownDate timeIntervalSinceNow]);
NSLog(@"Time interval: %f", timeInterval);
}
我会这样做: 向类中添加属性以存储最近一次触地的日期。最好是在
.m
-文件中的类扩展名中
@interface YourViewController ()
@property (nonatomic, strong) NSDate *buttonTouchDownDate;
@end
以编程方式或使用interface builder将按钮连接到触控按钮
和触控按钮内部
控制事件。这是非常详细的描述
然后存储按下按钮的日期。抬起手指时,计算存储日期与现在之间的时间间隔
- (IBAction)buttonDidTouchDown:(id)sender
{
self.buttonTouchDownDate = [NSDate date];
}
- (IBAction)buttonDidTouchUp:(id)sender
{
// Will return a negative value, so we use the ABS-macro.
NSTimeInterval timeInterval = ABS([self.buttonTouchDownDate timeIntervalSinceNow]);
NSLog(@"Time interval: %f", timeInterval);
}
可能的重复可能的重复