Ios changes the limit programmatically

I am using autolayout with a restriction. The upper observation space is 100

Now I want to change this so that when the user rotates the device into the landscape, the upper observation space is 50

Can this be done during development?

How can this be done at runtime?

+4
source share
1 answer

, 50 px 100 - , , " ", .

constraint, willRotateToInterfaceOrientation:duration: constant constraint layoutIfNeeded .

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

    self.myConstraint.constant = (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) ? 50. : 100.;
    [self.someView layoutIfNeeded];
}

( , , )

+18

Source: https://habr.com/ru/post/1532720/


All Articles