UISwipeGestureRecognizer * swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGesture:)];
輕掃方向
UISwipeGestureRecognizerDirectionRight
UISwipeGestureRecognizerDirectionLeft
UISwipeGestureRecognizerDirectionUp
UISwipeGestureRecognizerDirectionDown
設定輕掃方向,讓左右方向都存在 隻要枚舉值中又左移運算符,代表枚舉值可以通過按位或 | 讓多個枚舉值存在
warning :::::上下 和左右方向 在一個手勢識别器中不能同時存在
如果想要上下左右四個方法都有,就要建立兩個輕掃手勢對象,一個支援上下,一個支援左右.
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight ;
[redView addGestureRecognizer:swipeGesture];
[swipeGesture release];
- (void)swipeGesture :(UISwipeGestureRecognizer *)swipeGesture
{
NSLog(@"%u", swipeGesture.direction);
swipeGesture.view.backgroundColor = [UIColor random];
}
轉載于:https://blog.51cto.com/qccccc/1554908