0
如何在Xcode ver中使用UISwipeGestureRecognizer
來限制手勢識別的範圍。 5?建立手勢識別的域
下面是一些代碼:
- (void)viewDidLoad {
[super viewDidLoad];
// ...
[UIApplication sharedApplication].idleTimerDisabled = NO;
[UIApplication sharedApplication].idleTimerDisabled = YES;
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUp];
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeDown];
// ...
}
// ...
- (void)didSwipe:(UISwipeGestureRecognizer*)swipe{
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Swipe Left");
} else if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"Swipe Right");
} else if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(@"Swipe Up");
} else if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(@"Swipe Down");
}
}
我需要認識到只有在標籤手勢。
Thx很多,夥計們。
請注意,您可能必須在標籤上設置userInteractionEnabled = YES以便手勢識別器正常工作。因爲標籤通常不會響應觸摸事件。 –
哦,我看到..我會更新我的答案。謝謝。 –