2

Is it possible to replace this gesture in iOS 6 with a custom gesture? I have a gesture to show the map in full screen by hiding the status and navigation bars and it works but it also zooms every time it is done.

Here is how I currently have my gesture implemented.

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

in viewDidLoad:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toggleBars:)];
    tap.numberOfTapsRequired = 2;
    [self.view addGestureRecognizer:tap];
    tap.delegate = self;

gesture method:

- (void)toggleBars:(UITapGestureRecognizer *)gesture
{
    BOOL barsHidden = self.navigationController.navigationBar.hidden;

    if (!barsHidden)
    {
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        [self hideTabBar:self.tabBarController];
    }
    else if (barsHidden)
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
        [self showTabBar:self.tabBarController];
    }

    [self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
}

methods for hiding/showing the tab bar:

- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    float fHeight = screenRect.size.height;
    if(  UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width;
    }

    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
            view.backgroundColor = [UIColor blackColor];
        }
    }
    [UIView commitAnimations];
}

- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fHeight = screenRect.size.height - 49.0;

    if(  UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width - 49.0;
    }

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
        }
    }
    [UIView commitAnimations];
}
raginggoat
  • 3,570
  • 10
  • 48
  • 108
  • You can probably stick a custom double tag gesture recognizer on the view and handle that. Haven't tried that though. – Linuxios Aug 13 '13 at 16:48
  • I've updated my post with my current implementation. – raginggoat Aug 13 '13 at 16:55
  • Why would you want to do that? In all maps on iOS people double tap to zoom in. That's what they have been trained to do and now you're going to make your app respond differently to what the user expects. From a usability point of view this is a bad idea. You should try adding a little double arrow in the corner like Mountain Lion does. Or a box of four arrows, but leave the standard gestures alone for your user's sake. – Craig Aug 13 '13 at 20:07
  • My thought was that most people use pinch to zoom (at least most people I know do). Also, I have some other views in my app that use the tap gesture to hide the top and bottom bars so I wanted it to stay uniform throughout the app. – raginggoat Aug 13 '13 at 20:10
  • http://stackoverflow.com/questions/9008975/how-to-tap-to-zoom-and-double-tap-to-zoom-out-with-uiscrollview/9009554#9009554 – GWed Feb 17 '14 at 16:14

0 Answers0