TheLearner
TheLearner

Reputation: 19507

Swiping gestures in iPad

Is it possible to implement a solution that allows one to swipe in a certain way across the screen and then trigger an event of some kind to load another UIView for e.g.Wikipedia app

My problem is that I want it to be over my MKMapView - but I am guessing it would interfere with the map.

Does anyone have a simple code snippet?

Upvotes: 0

Views: 429

Answers (2)

Ned
Ned

Reputation: 6270

As nduplessis said, UIGestureRecognizer will do it. It should be able to differentiate between dragging the map and performing the swipe gesture, so you should be fine.

Creating and adding the gesture recognizer:

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[mapView addGestureRecognizer:swipeRight];

Reacting to the gesture:

- (void)swipeRightAction:(UISwipeGestureRecognizer *)gestureRecognizer
{
//Switch views...(do this however you have been switching views)
[mapView.superview addSubview:wikipediaView];
[mapView removeFromSuperview];
}

Upvotes: 2

nduplessis
nduplessis

Reputation: 12436

You should be able to do this with UIGestureRecognizers

Upvotes: 2

Related Questions