如何根据持有 UIButton 的时间加载视图?
我正在开发一个 iOS 应用程序,我想在 UIButton 按住 x 秒时加载一个视图,如果按住 x+y 秒则加载另一个视图,等等。我找到了一个教程。我遇到的问题是,如何切换按钮按下的长度?本教程切换了点击次数。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
switch ([allTouches count])
{
case 1: // Single touch
{
// Get the first touch.
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
switch ([touch tapCount])
{
case 1: // Single Tap.
{
// Start a timer
timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showAlertView:) userInfo:nil repeats:NO];
[timer retain];
}
break;
case 2: // Double tap.
break;
}
}
break;
case 2: // Double touch
{
}
break;
default:
break;
}
}
有什么建议吗?
I'm working on an iOS app where I want to load one view if a UIButton is held for x seconds, another if it's held for x+y seconds, etc. I found a tutorial. The problem I'm running into is, how do I switch the length of the button press? The tutorial switched the number of taps.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
switch ([allTouches count])
{
case 1: // Single touch
{
// Get the first touch.
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
switch ([touch tapCount])
{
case 1: // Single Tap.
{
// Start a timer
timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showAlertView:) userInfo:nil repeats:NO];
[timer retain];
}
break;
case 2: // Double tap.
break;
}
}
break;
case 2: // Double touch
{
}
break;
default:
break;
}
}
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我得到了答案。我刚刚在触地事件中启动了 NSTimer,并在内部触地事件中停止。
I got my answer. I just started an NSTimer on a touch down event, and stopped in on touch up inside.
使用 UILongPressGestureRecognizer 类。 Apple 在 3.2 中记录了这一点 -
http://developer.apple.com/iphone/prerelease/library/documentation/General/Conceptual/iPadProgrammingGuide/GestureSupport/GestureSupport.html#//apple_ref/doc/uid/TP40009370-CH5-SW1< /a>
Use the UILongPressGestureRecognizer class. Apple has this documented in 3.2 -
http://developer.apple.com/iphone/prerelease/library/documentation/General/Conceptual/iPadProgrammingGuide/GestureSupport/GestureSupport.html#//apple_ref/doc/uid/TP40009370-CH5-SW1