Я добавил свой собственный uiview для self.view. Поскольку мы не можем установить ограничения в раскадровке в этом сценарии, я попытался добавить программно.Установите программные ограничения для uiview, чтобы поддерживать как портрет/пейзаж
Следящий за этим How to Create layout constraints programmatically.
Я использую код ниже.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[customView setNeedsUpdateConstraints];
}
-(void)updateViewConstraints
{
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
[self.view addConstraints:@[
//view1 constraints
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:padding.top],
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:padding.left],
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:-padding.bottom],
[NSLayoutConstraint constraintWithItem:customView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1
constant:-padding.right],
]];
}
Я зову [self updateViewConstraints]
от viewDidLoad
, но до сих пор я получаю половину вид на пейзаж.
Любая идея по этому вопросу. Заранее спасибо.
Если вы не указали нам ограничения, которые вы добавили, как мы можем предоставить ответ? – Lefteris
@Lefteris Я добавил ссылку, которая использовала те же ограничения. –