iOS iOS6 iOS7 iPadアプリ iPhoneアプリ Xcode アプリ開発

UISwipeGestureRecognizerを使用して、スワイプを検知する方法。

iOSにて、UISwipeGestureRecognizerを使用して、スワイプを検知する方法。

スワイプを用いたアプリを作成する場合は、以下のやり方が一番簡単。スワイプを検知したら、何かの処理を書き加えるだけで、その機能を果たすことができるようになります。

ただし、1本指でのスワイプ。

- (void)setupSwipeGesturea
{
    UISwipeGestureRecognizer *SwipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeLeft:)];
    [SwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:SwipeLeft];

    UISwipeGestureRecognizer *SwipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeRight:)];
    [SwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    [[self view] addGestureRecognizer:SwipeRight];

    UISwipeGestureRecognizer *SwipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeUp:)];
    [SwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
    [[self view] addGestureRecognizer:SwipeUp];

    UISwipeGestureRecognizer *SwipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeDown:)];
    [SwipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
    [[self view] addGestureRecognizer:SwipeDown];
}

- (void)SwipeLeft:(UITapGestureRecognizer *)recognizer {
    NSLog(@"left");
}

- (void)SwipeRight:(UITapGestureRecognizer *)recognizer {
    NSLog(@"right");
}

- (void)SwipeUp:(UITapGestureRecognizer *)recognizer {
    NSLog(@"up");
}

- (void)SwipeDown:(UITapGestureRecognizer *)recognizer {
    NSLog(@"down");
}

-iOS, iOS6, iOS7, iPadアプリ, iPhoneアプリ, Xcode, アプリ開発
-, , , , , , , ,

Copyright© LAPTURE , 2020 All Rights Reserved.