0

I am moving with Navigation bar by this method to another location:

- (void)shiftNavigationBar
{
    self.navigationController.navigationBar.layer.zPosition = 0;
    float currentVersion = 7.0;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= currentVersion) {
        UINavigationBar *navBar = self.navigationController.navigationBar;
        [self.navigationController.navigationBar
         setFrame:CGRectMake(navBar.frame.origin.x, 92, navBar.frame.size.width, navBar.frame.size.height)];
    }
}

I do this in viewDidAppear and when controller is loaded for first time it's okay. But when I click home button and returns to application navigation bar disappear (ok, it didn't disappear I have another bar in place where normally is navigation bar so it "hides" above this bar) and I need to shift navigation bar again but I tried different methods (Will/DidAppear and so) but It's looks that noone is execute when returning from inactive. I know there is method for this in AppDelegate but what method I can use in controller?

Edit: Methods which I tried but It didn't worked:

1- Add method shiftNavigationBar to AppDelegate and call it in applicationDidBecomeActive

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [self shiftNavigationBar];
}

- (void)shiftNavigationBar
{
    ((UINavigationController*)self.window.rootViewController).navigationBar.layer.zPosition = 0;
    float currentVersion = 7.0;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= currentVersion) {
        UINavigationBar *navBar = ((UINavigationController*)self.window.rootViewController).navigationBar;
        [((UINavigationController*)self.window.rootViewController).navigationBar
         setFrame:CGRectMake(navBar.frame.origin.x, 92, navBar.frame.size.width, navBar.frame.size.height)];
    }
}

2- Call controller method from AppDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application
{

    UINavigationController *navController = (UINavigationController*)self.window.rootViewController;
    [(MAListRepositoriesVC*)navController.topViewController doMyLayoutStuff:self];
}
// I added shiftNavigationBar to method doMyLayoutStuff

3- Observer in controller

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doMyLayoutStuff:) name:UIApplicationDidBecomeActiveNotification object:nil];

Everytime method was called but everytime navigation bar is back at top. It looks like methods are called too soon and after that there are next changes and returns navigation bar back to top.

Edit2: As right answer I choose answer with replace navigation bar with custom view because that's what I must do. I tried many solutions which I can find but nothing help me. So I created custom view which looks like I need and mainly which is there where I put it.

Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182

3 Answers3

1

Can you post a screenshot or mock of the UI?

Probably you should look for a custom view and replace the navigation bar entirely as modifying it is clumsy and will surely break on future updates. Besides it may risk to get your app rejected.

Rivera
  • 10,792
  • 3
  • 58
  • 102
0

Try this... It's just a temporary fix you said that seems that your methods get called to early when then just delay them a little bit using the method:

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

Just add probs 0.5-1.0 for the seconds, target is obviously self and selector will be @selector(shiftNavigationBar), userInfo nil, and repeats NO.

I'm not to sure about the bar that you mention appears above your desired bar. Do you call that bar using a method? does it load from a nib file? if you can clarify a little bit more I could help you more with this issue. I have an app that uses a custom navigation bar it works just fine but I need a bit more of detail to help you.

Hope this suggestion helps you at least to troubleshoot your issue.

artud2000
  • 544
  • 4
  • 9
0

One possibility would be to put the navBar into a different superview, and then to adjust the frame of the new superview. For example, in your navigation controller viewDidLoad (or awakeFromNib, if it's loaded from a Storyboard/XIB):

// Move the current self.view to contentView, create a new self.view,
// and add the contentView to this new view.
self.contentView = self.view; // navBar is a subview of self.view
self.view = [[UIView alloc] initWithFrame:self.contentView.frame];
CGRect contentFrame = CGRectMake(0,92,self.view.frame.size.width, self.view.frame.size.height-92);
self.contentView.frame = contentFrame;
[self.view addSubview:self.contentView];

(You will need to add a new property to the interface: @property (strong, nonatomic) UIView *contentView;). I leave it to you to add in the code for the different device versions.

This seems to survive backgrounding/becoming active, so you don't need code in your AppDelegate.

pbasdf
  • 21,386
  • 4
  • 43
  • 75