公司項(xiàng)目里用URBMediaFocusViewController來
animates thumbnail previews of your media to their full size versions with physics similar to Tweetbot 3.
結(jié)果當(dāng)單擊圖片后發(fā)現(xiàn)圖片的彈出速度比較慢。后來發(fā)現(xiàn)是因?yàn)橥瑫r(shí)在圖片上添加了單擊和雙擊倆種手勢(shì)妆距。為了區(qū)分單擊和雙擊使用了[singleTapGestureRecognizer requireGestureRecognizerToFail: doubleTapGestureRecognizer];
方法寒匙,但是這個(gè)區(qū)分單擊和雙擊的時(shí)間有點(diǎn)長纽谒,因而導(dǎo)致了圖片彈出速度有點(diǎn)慢禀忆。根據(jù)How to recognize oneTap/doubleTap at moment? 這個(gè)答案改寫出下面的代碼。
#import "HBJFShortTapGestureRecognizer.h"
#define DELAY_SECONDS 0.28
@implementation HBJFShortTapGestureRecognizer
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(DELAY_SECONDS * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.state != UIGestureRecognizerStateRecognized) {
self.state = UIGestureRecognizerStateFailed;
}
});
}
@end
注意:在頭文件里要添加#import <UIKit/UIGestureRecognizerSubclass.h>
。
在看這個(gè)代碼里的時(shí)候突然對(duì)UITapGestureRecognizer
的UIGestureRecognizerState
感到很迷惑。
typedef enum {
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
} UIGestureRecognizerState;
上面是所有的UIGestureRecognizerState
降传,而且里面UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
很是讓我不解。在detecting finger up/down UITapGestureRecognizer上面查到
UITapGestureRecognizer is a discrete gesture recognizer, and therefore never transitions to the began or changed states. From the UIGestureRecognizer Class Reference:
Discrete gestures transition from Possible to either Recognized (UIGestureRecognizerStateRecognized) or Failed (UIGestureRecognizerStateFailed), depending on whether they successfully interpret the gesture or not. If the gesture recognizer transitions to Recognized, it sends its action message to its target.
從這里可以知道勾怒,UITapGestureRecognizer
是discrete手勢(shì)婆排,不是continuous手勢(shì),因而UITapGestureRecognizer
只有3種UIGestureRecognizerState
即UIGestureRecognizerStatePossible
UIGestureRecognizerStateRecognized
和UIGestureRecognizerStateFailed
笔链。而continuous手勢(shì)的UIGestureRecognizerState
為UIGestureRecognizerStatePossible
UIGestureRecognizerStateBegan
UIGestureRecognizerStateChanged
UIGestureRecognizerStateEnded
和UIGestureRecognizerStateCancelled
到此段只,所有的疑惑都解決了。