3.2より前のバージョンをサポートしたいのですが、これは協力したくない唯一のシンボルです.touchesmovedコードまたはUILongPressGestureRecognizerの代わりに使用できるものを知っている人はいますか?
ありがとう、
ニック
3.2より前のバージョンをサポートしたいのですが、これは協力したくない唯一のシンボルです.touchesmovedコードまたはUILongPressGestureRecognizerの代わりに使用できるものを知っている人はいますか?
ありがとう、
ニック
ご存知のように、3.2 より前の iOS では touchesBegan、Moved、Ended、および Canceled 関数を使用する必要があります。touchesMoved のみを実装するのは悪いと思います。ユーザーが押して離すまでまったく動かない場合、 touchesMoved は呼び出されないからです。
代わりに、NSTimer を使用して長押しタッチ イベントを実現しました。これは最適な解決策ではないかもしれませんが、私のアプリではうまくいきました。コードのスニペットを次に示します。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
isAvailable = NO;
timer = [NSTimer scheduledTimerWithTimeInterval:DURATION target:self selector:@selector(didPassTime:) userInfo:nil repeats:NO];
}
- (void)didPassTime:(id)sender{
isAvailable = YES;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
if(isAvailable == YES){
// still pressing after 0.5 seconds
}
else{
// still pressing before 0.5 seconds
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if(isAvailable == YES){
// releasing a finger after 0.5 seconds
}
else {
// releasing a finger before 0.5 seconds
[timer invalidate];
timer = nil;
}
}