Tha*_*nka 4 iphone events touch
如何在iPhone屏幕上跟踪触摸事件2秒钟.就像在Safari中保存图像一样,添加到UIWebView中的图像?
Noa*_*oon 10
+scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:在视图的-touchesBegan:withEvent:方法中创建NSTimer ,并取消它(使用-invalidate)in -touchesEnded:withEvent:.如果其选择器指向的方法被调用,则用户将其手指放在视图上,无论您将计时器的间隔设置为何时.例:
接口(.h):
@interface MyView : UIView
...
NSTimer *holdTimer;
@end
Run Code Online (Sandbox Code Playgroud)
实施(.m):
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt
{
[holdTimer invalidate];
holdTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(touchWasHeld) userInfo:nil repeats:NO];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt
{
[holdTimer invalidate];
holdTimer = nil;
}
- (void)touchWasHeld
{
holdTimer = nil;
// do your "held" behavior here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
566 次 |
| 最近记录: |