スマートフォンのアプリを開発する上で避けて通れないタッチジェスチャーの中から、スワイプと長押し(ロングプレス)のジェスチャーを実装する場合のメモ。
INDEX
スワイプ・長押し(ロングプレス)ジェスチャーを実装する
- スワイプアップ
- [code]
UISwipeGestureRecognizer *swipeUpGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUpGesture:)];
swipeUpGesture.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUpGesture];– (void) handleSwipeUpGesture:(UISwipeGestureRecognizer *)sender
{
NSLog(@”swipe Up”);
}
[/code]
- ロングプレス
- [code]
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
longPressGesture.minimumPressDuration = 1;
[self.view addGestureRecognizer:longPressGesture];– (void) handleLongPressGesture:(UILongPressGestureRecognizer*) sender
{
NSLog(@”long press”);
}
[/code]
まとめ
Objective-Cはソースコードの見た目にさえ慣れてくると、iPhone特有の機能を実装するのは比較的簡単にできる。ジェスチャーはiOSやAppleの標準アプリの実装例を参考にしながら、自身のアプリに取り入れることでUXの向上につながりますね。