0

By default, when swipe a mapkit view, the map moves. This is great.

If I want to move away from the map view and load another viewcontroller's view, how do I accomplish that? I could add a button to do that, but I'd like to use gesture.

Thanks

THE FOLLOWING CODE WORKED:

(1) In the map view controller's header file, I added UIGestureRecognizerDelegate to support its protocol

(2) In map view controller's .m file , I added

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
   shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

(3) In map view controllers viewDidLoad method I added:

UISwipeGestureRecognizer *leftSwipe = 
[[[UISwipeGestureRecognizer alloc] 
  initWithTarget:self action:@selector(leftSwipeReceiver:)] autorelease];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
leftSwipe.delegate = self;
[self.view addGestureRecognizer:leftSwipe];

(4) This follow function is called for a left-swipe

- (void)leftSwipeReceiver:(UIGestureRecognizer *)recognizer
{
    NSLog(@"leftSwipeReceiver:");

}
user675823
  • 23
  • 2
  • 7
  • You can use a UISwipeGestureRecognizer and require say two touches for the "move away" swipe so user can still swipe the map but this doesn't seem natural. How will the user know to do that? If you have/make space to show help text, just put a button there. –  Oct 04 '11 at 12:32
  • It is really a good question how the user will know about the "move away". I am also struggling with this. The user is able to swipe from the other view to the map view, so I wanted it to have similar behavior. Also, I experimented with implementing UISwipeGestureRecognizer, the swipe events do not seem to get to the specified handlers, but intercepted by the map view. – user675823 Oct 04 '11 at 21:49
  • To prevent the intercept, you need to implement `shouldRecognizeSimultaneouslyWithGestureRecognizer` and return YES. See the bottom half of [this answer](http://stackoverflow.com/questions/6941199/how-to-get-click-event-from-a-button-added-over-mkannotationview/6942854#6942854) which explains how with a UITapGestureRecognizer but it's the same idea. –  Oct 04 '11 at 21:59
  • Thanks so much let me give it a try and will update back... – user675823 Oct 04 '11 at 22:46
  • It did not work (yet). Why this edit area does not accept "return" to change line? – user675823 Oct 05 '11 at 00:22
  • Since I couldn't add more text in here, I added more info in my original question. See above. – user675823 Oct 05 '11 at 00:27
  • Anna Karenina: You are my hero. The code I added to the original posting actually worked!!! Thanks... – user675823 Oct 05 '11 at 00:50

0 Answers0