iPad에서 mainviewcontroller의 팝업과 같이 viewcontroller를 잘 보여 주므로 잘 동작합니다. 하지만 현재는 화면에 맞게 prefferedContentSize를 설정하고 있으므로 크기를 자동 변환하지 않습니다. 나는 가로 세로 97 %와 세로 90 %의 mainviewcontroller에 정렬 된 가운데가되도록 popupview가 필요합니다. 그래서 이제 popupViewController에 autolayout 제약 조건을 추가하려고 시도하고 있지만 확실하지는 않습니다. 아래는 지금까지 시도한 코드입니다. 이는 '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]];
}
왜 subViews에 대한 참조로서 self.view에 제약 조건을 추가하는지. 제약을 추가 할 필요가 없습니다. 어떤 뷰를 self.view의 하위 뷰로 추가하면 제약 조건을 추가해야합니다. –
제시하고있는 두 번째 뷰 컨트롤러의 높이와 너비는 크기가 조정되지 않습니다. 크기를 조정하려면 어떻게해야합니까? 한 가지 방법은 viewwilltransition에 크기를 추가하는 것입니다. – Gamerlegend