Это правда, что до 3.2 UISwipeGestureRecognizer компилируется без предупреждений или ошибок, как указано ранее, но, однако, у меня возникла проблема по этому поводу. Мое приложение было скомпилировано, но когда я запустил свое приложение на iphone 3.1, UISwipeGestureRecognizer дважды обнаружил событие смахивания. Итак, я сделал условное кодирование. Моя реализация:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version < 3.2) {
UITouch *touch = [touches anyObject];
startPosition = [touch locationInView:self];
}
[super touchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version < 3.2){
UITouch *touch = [touches anyObject];
CGPoint endPosition = [touch locationInView:self];
if (endPosition.x-startPosition.x>30) { //difference between end and start must be min. 30 pixels to be considered as a swipe. if you change it as startPosition.x-endPosition.x you could detect left swipe
[self handleSwipe]; //my swipe handler
}
}
[super touchesEnded:touches withEvent:event];
}
и в другом методе, скажем, в viewdidload
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.2){
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipe)];
[self addGestureRecognizer:swipe];
}
Эта реализация избавляет вас от риска использования закрытого API, хотя сейчас оно не является частным. Кроме того, это устраняет проблему с повторяющимся проведением пальца.