开发者

Swipe gesture iphone

I have some trouble to handle swipe on iPhone, I create in my interface a UISwipeGestureRecognizervar:

UISwipeGestureRecognizer *swipeRecognizer;

and in my controller : viewDidLoad method

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Horizontal swipe
    swipeRecognizer =开发者_JS百科 [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                                          action:@selector(swipeMethod:)];
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft; 
    [self addGestureRecognizer:swipeRecognizer];
}

And my method to handle swipe is :

-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
    NSLog(@"Swipe!");   
}

When I run my code and do a swipe I got nothing? I'm supposed to get : Swipe!

Thanks.


I'm surprised that doesn't crash with an unrecognized selector error. Try adding the recognizer to your view instead of to your view controller:

[self.view addGestureRecognizer:swipeRecognizer]


swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

Does this work?

Don't you have to add two gestureRecognizer for each direction?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜