Я представляю viewcontroller как всплывающее окно с моего mainviewcontroller на iPad, который отлично работает. Но в настоящее время я устанавливаю свой prefferedContentSize для установки на экран, поэтому, когда я поворачиваю размер, не авторезистентно. Мне нужно, чтобы popupview выравнивался по центру с mainviewcontroller шириной 97% и высотой 90% в портретной и альбомной ориентации. Поэтому я теперь пытаюсь добавить ограничение автоопределения на свой popupViewController, но не знаю, как это сделать. Ниже приведен код, который я пробовал до сих пор. Это дает мне об ошибке «NSInternalInconsistencyException»Автоматическое добавление ограничений автоопределения при представлении ViewController
#import "ViewController.h"
@interface ViewController()
{
PopUpViewController *popUpController;
}
@end
- (IBAction)showPopUp:(UIButton *)sender {
popUpController = [[PopUpViewController alloc]initWithNibName:@"PopUpViewController" bundle:nil];
popUpController.view.center = self.view.center;
popUpController.view.layer.cornerRadius = 8.0f;
popUpController.view.layer.masksToBounds = YES;
popUpController.view.layer.borderWidth = 1.0f;
popUpController.view.layer.borderColor = [UIColor blueColor].CGColor;
popUpController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
popUpController.modalPresentationStyle = UIModalPresentationFormSheet;
// CGPoint frameSize = CGPointMake([[UIScreen mainScreen] bounds].size.width*0.97f, [[UIScreen mainScreen] bounds].size.height*0.9f);
// popUpController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y);
[self addConstraint];
[self.navigationController presentViewController:popUpController animated:YES completion:nil];
}
-(void)addConstraint
{
// Width constraint, half of parent view width
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:popUpController.view.superview
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeWidth
multiplier:0.97
constant:0]];
// Height constraint, half of parent view height
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:popUpController.view.superview
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeHeight
multiplier:0.9
constant:0]];
// Center horizontally
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:popUpController.view.superview
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0]];
// Center vertically
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:popUpController.view.superview
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0.0]];
}
Почему вы добавляете ограничения на self.view, поскольку это ссылка на subViews. Не нужно добавлять ограничение. Когда вы добавляете какое-либо представление в виде subview для self.view, вам нужно добавить ограничения. –
Высота и ширина для второго контроллера представления, который я представляю, не изменяет размер. Что мне делать для изменения размера? Один из способов - добавить размер в viewwilltransition, но не выглядит красивым во время анимации. – Gamerlegend