ビューコントローラでNSTimer
プロパティを設定してみてください。ボタンが押されたら、タイマーを作成してプロパティに割り当てます。内側のキャンセルtouch上で実行するアクション、またはタッチを設定すると
-(void) startHoldTimer {
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(goToNewView:) userInfo:nil repeats:NO];
}
:
[button addTarget:self action:@selector(touchUp) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(cancelTimer) forControlEvents:UIControlEventTouchCancel];
を
[button addTarget:self action:@selector(startHoldTimer) forControlEvents:UIControlEventTouchDown];
及びこれに割り当てる:あなたはこれでその瞬間を検出することができます
および
//if timer fires, this method gets called
-(void) goToNewView {
[self cancelTimer];
[self loadSecondView];
}
// normal button press invalidates the timer, and loads the first view
-(void) touchUp {
[self cancelTimer];
[self loadFirstView];
}
//protected, just in case self.myTimer wasn't assigned
-(void) cancelTimer {
if (self.myTimer != nil)
if ([self.myTimer isValid]) {
[self.myTimer invalidate];
}
}
それの世話をする!