2
votes

So i decided to try and build an iPhone application using StoryBoarding. And i got a basic tab-based application set up, quite fast.

TabBar controller as initial View controller with two tabs. On each tab some more views attached as content.

On one tab i have navigation controller that has few more views following. Here i have no problems. I can move back and forth using custom buttons and navigation bar. Also TabBar is always at its place during all movements through the views.

Then i got the second tab. No Navigation controller here, because, on second tab I need to use custom seques to create custom transition animations between views. No problem with seques, animations and transitions so far(at least i almost got the animation i need :) ). But where i'm stuck is that TabBar. As soon as I press any button that will navigate to another view using custom seque i lose my TabBar. Even if i navigate back to initial view there are no TabBar anymore.

I've read something about popping up the tabbar controller in the views stack, but all samples I could find just did not work for me.

If anyone got stuck with similar thing, please share the solution. Any pointing to some good tutorial or sample would be very appreciated.

edit: So my custom seque looks like this:

my "(void)perform" looks something like this: (at least it animates from source to destination as expected. the only thing that is wrong, is that TabBar gets hidden or dismissed)

#import "XCustomSeque.h"
#import <QuartzCore/QuartzCore.h>
@implementation XCustomSeque
@synthesize appDelegate=_appDelegate;
-(void) perform{
    UIViewController *srcViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destViewController = (UIViewController *) self.destinationViewController;

    self.appDelegate = [[UIApplication sharedApplication] delegate];

    CATransition* trans = [CATransition animation];    
    [trans setType:kCATransitionMoveIn];
    [trans setFillMode:kCAFillModeBoth];
    [trans setDuration:1];
    [trans setSubtype:kCATransitionFromLeft];

    CALayer *layer = destViewController.view.layer;

    [srcViewController.view removeFromSuperview];
    [self.appDelegate.window addSubview:destViewController.view];
    [layer addAnimation:trans forKey:nil]; 

    self.appDelegate.window.rootViewController=destViewController;
}
@end
2
In the second tab, I think you are using "Modal" segue (not seque). It means that you are opening a modal full screen view over the existing view hierarchy including tab bar, and when you "navigate back" (I think you've created another modal segue), you open another modal full screen view. The right way to "navigate back" is calling [self dismissModalViewControllerAnimated:YES].hoshi
No it is not "Modal" seque in second Tab. With Modal it were not possible to use the Custom seque with custom animation.tigukargas
Ok i tried all kind of different seque types. 1) Push 2) Modal 3) Custom | The only one that does not hide the TabBar is number one - Push. The bad side of this seque is that it is not possible(I did not find any way to do it) to apply any custom animations for transitions here. So push is simply out of question.tigukargas

2 Answers

1
votes

In second tab, you also need to use navigation controller, but with "Shows Navigation Bar" off. Your storyboard looks like the following.

        +-> [NavC-1] --> [VC-1-1] --(push)-> [VC-1-2] ...
        |   (shows nav bar)
[TabC] -+
        |
        +-> [NavC-2] --> [VC-2-1] --(custom)-> [VC-2-2]
            (hides nav bar)

When you navigate from VC-2-1 to VC-2-2, you use a custom segue (a subclass of UIStoryboardSegue), with -perform method like following. (See How to create custom modal segue in 4.2 Xcode using storyboard)

- (void)perform
{
    UIViewController *src = self.sourceViewController;
    UIViewController *dst = self.destinationViewController;
    [UIView transitionWithView:src.navigationController.view duration:0.2
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{
                        [src.navigationController pushViewController:dst animated:NO];
                    }
                    completion:NULL];
}

When you navigate back from VC-2-2 to VC-2-1, you don't want to use segue because it creates new copy of VC-2-1. Instead, you use an action method (called when the back button is pressed) like following.

- (IBAction)goBack:(id)sender
{
    [UIView transitionWithView:self.navigationController.view duration:0.2
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:^{
                        [self.navigationController popViewControllerAnimated:NO];
                    }
                    completion:NULL];
}
0
votes

So after messing around on internet with various samples and while still none seemed to work as expected I dropped my custom seque animation for later hacking. Decided to stick with almost somewhat that Hoshi suggested. At least i got my tab bar always visible and there's even less code for animations.

So with StoryBoarding i ended up with this (a bit different than Hoshi's suggestion):

        +-> [NavC-1] --> [VC-1-1] --(push)-> [VC-1-2] ...
        |   (shows nav bar)
[TabC] -+
        |
        +-> [NavC-2] --> [VC-2-1] --(push)-> [VC-2-2]
            (hides nav bar)

I used standard Push Seque for Forward Slide Transition (No code written here, everything is on StoryBoard)

Then on second branch i needed to have a view without navigation bar and with custom back button which when pressed would start Backward Slide Transition. Of-course, Tab bar must stay where it is. Navigation bar were easy to hide, just untick the "Shows Navigation Bar" in [NavC-2] attributes panel. Now to get the Backward Slide Transition I created custom class for every View Controller in second branch and filled them with this:

#import "VC_2_1.h"   
@implementation VC_2_1

- (IBAction)on_back_button_pressed:(id)sender 
{
    [self.navigationController popViewControllerAnimated:YES]; 
}

@end

on_back_button_pressed is the thing called by the back button on [VC-2-1]. Same goes for [VC-2-2] and any other VC following in second branch.

And all this folks gave me exactly what i needed. Press custom buttons and navigate between views using slide left and right animations. And tabbar is not getting lost. :)

in fact the key to the problem was this line, same as Hoshi suggested.

[self.navigationController popViewControllerAnimated:YES];

this was the only way that gave me backward slide animation when pressed on custom button(not back button on standard navigation bar)

Cheers!