Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27159

UINavigationController frame issue

I have UINavigationController in my view controller A

@property (nonatomic, strong) UINavigationController *containerNavigationController;

In view controller A I have init method

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if (self)
    {
        _containerNavigationController = [UINavigationController new];

       _containerNavigationController.navigationBarHidden = YES;
    }

    return self;
}

In view did load method I have this code:

[self.view addSubview:_containerNavigationController.view];

[_containerNavigationController.view setFrame:CGRectMake(247, 64, 700, 700)];

As you can see that the height of nag view os 700, but when I run app I can see about 400 pt of nag view height. But if I set for example 10000 for height it is display all views. so I have another controller that is a root view controller of _containerNavigationController that why I can check if some view of root view controller hidden or not. So when the heigh is 700 I see just half of root view but when height is 10000 I can see whole view

I set root when I pressed on some button in view controller A

vc = (UIViewController *)[sb instantiateViewControllerWithIdentifier:@"STScheduelPlayersViewController"];

[_containerNavigationController setViewControllers:@[vc] animated:YES];

this is log in view did load when rect was set

(lldb) po _containerNavigationController.view
<UILayoutContainerView: 0x8b3afd0; frame = (247 64; 778 777); autoresize = W+H; gestureRecognizers = <NSArray: 0x8b39350>; layer = <CALayer: 0x8b3b460>>

this log when i tap on button

(lldb) po _containerNavigationController.view
<UILayoutContainerView: 0x8b3afd0; frame = (247 64; 1034 521); autoresize = W+H; gestureRecognizers = <NSArray: 0x8b39350>; layer = <CALayer: 0x8b3b460>>

Upvotes: 0

Views: 1023

Answers (1)

Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27159

Wondering but autoresize mask solve this problem:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if (self)
    {
        _containerNavigationController = [UINavigationController new];
        [_containerNavigationController.view setFrame:CGRectMake(247, 64, 778, 777)];
        _containerNavigationController.view.autoresizingMask = UIViewAutoresizingNone;
        _containerNavigationController.navigationBarHidden = YES;
    }

    return self;
}

Upvotes: 2

Related Questions