我想延迟震动5秒钟,因为如果用户持续摇动设备,则响应显示为空。所以这就是为什么我要把震动推迟到n,除非响应还活着。
这是我的代码
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
[FlurryAnalytics logEvent:@"User shaked to update"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CheckWeather" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"startWeatherNeue" object:nil];
if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
[super motionEnded:motion withEvent:event];
}
}
答案 0 :(得分:1)
要稍后执行某些选择器,您可以使用:
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
答案 1 :(得分:1)
在目标c中我使用 sleep(6)进行停止处理, 把睡眠(6)放在你被解雇的通知代码中: -
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake) {
sleep(6);
[FlurryAnalytics logEvent:@"User shaked to update"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CheckWeather" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"startWeatherNeue" object:nil];
if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
[super motionEnded:motion withEvent:event];
}
}
然后处理停止6秒钟,然后在6次借调后通知点火可能对你有帮助
其他强>
你也使用NSTimer: -在NSTimer中你在if else条件下检查你的响应数组计数> 0,当你的响应数组>时,用1秒调用方法0然后调用NSNOtification方法
这里是我的例子: - 使用NSTimer
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
self.TimeOfActiveUser = [NSTimer scheduledTimerWithTimeInterval:01.0 target:self selector:@selector(checkInfoString) userInfo:nil repeats:YES];
}
-(IBAction)checkInfoString
{
if([responsearray count]>0)
{
[FlurryAnalytics logEvent:@"User shaked to update"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CheckWeather" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"startWeatherNeue" object:nil];
if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
{
[super motionEnded:motion withEvent:event];
}
}
else
{
NSLOG
}
}