Tôi có một số rắc rối để xử lý swipe trên iPhone
, tôi tạo ra trong giao diện của tôi một var UISwipeGestureRecognizer
:Swipe cử chỉ iphone
UISwipeGestureRecognizer *swipeRecognizer;
và trong điều khiển của tôi: viewDidLoad
phương pháp
- (void)viewDidLoad
{
[super viewDidLoad];
// Horizontal swipe
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeRecognizer];
}
Và phương pháp của tôi để xử lý swipe là:
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(@"Swipe!");
}
Khi tôi chạy mã và d o một swipe tôi đã không có gì? Tôi phải nhận được: Swipe!
Cảm ơn.
Không thêm nó vào chính bản thân, hoặc sử dụng self.view (giả sử bản thân là một bộ điều khiển xem) hoặc sử dụng chế độ xem phụ để đặt trình nhận dạng cử chỉ. Bạn có thể đặt điểm ngắt trước khi đặt trình nhận dạng và xem nó có được thêm chính xác hay không. Xem câu trả lời của tôi cho phát hiện swipe trái và phải: http://stackoverflow.com/a/16810160/936957 –