Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController: Title Jumps in Resize Animation

I have an ipad app where i would like to hide and show a category list (kind of like the small view in a split view controller), and the main view which contains a UiNavigationController stack.

I would like to resize the UINavigationController view to fill the whole screen when the category list is hidden, and to shrink when i show the list.

I have it working, except the title of the navigation bar immediately jumps to its new offset when setting the frame within an animation begin/commit block.

Any ideas how to stop the jump of the title?

like image 213
Nick Hingston Avatar asked Jan 21 '11 11:01

Nick Hingston


1 Answers

I used this for fixing those jumps in UINavigationBar for title and right button.

#import "UINavigationBar+My.h"

@implementation UINavigationBar (My)

- (void)layoutSubviews {
for (id obj in [self subviews]) {
    if ([NSStringFromClass([obj class]) isEqualToString:@"UINavigationItemView"])
        [(UIView *)obj setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin];
    else if ([NSStringFromClass([obj class]) isEqualToString:@"UIButton"]) {
        if ([(UIButton *)obj center].x < ([self center].x / 2))
            [(UIButton *)obj setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
        else
            [(UIButton *)obj setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
    }
}

@end

I hope it will help you ;-)

like image 57
Adam Avatar answered Dec 14 '22 23:12

Adam