It is necessary with the help of NSLayoutConstraint
configure the placement of the testView
at a fixed distance under the UINavigationBar
. The problem is that the height of the UINavigationBar
changes as the screen rotates.
How to set up the restrictions for changing the height of the UINavigationBar
?
see block "// Y" in the example code
self.testView = [[UIView alloc] initWithFrame:CGRectZero]; [self.testView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.view addSubview:self.testView]; // Width [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.testView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:100]]; // Height [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.testView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:100]]; // Y [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.testView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:70.f]]; // X [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.testView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]];
The result now looks like this: