2016-06-09 5 views
0

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]]; 
} 
+0

왜 subViews에 대한 참조로서 self.view에 제약 조건을 추가하는지. 제약을 추가 할 필요가 없습니다. 어떤 뷰를 self.view의 하위 뷰로 추가하면 제약 조건을 추가해야합니다. –

+0

제시하고있는 두 번째 뷰 컨트롤러의 높이와 너비는 크기가 조정되지 않습니다. 크기를 조정하려면 어떻게해야합니까? 한 가지 방법은 viewwilltransition에 크기를 추가하는 것입니다. – Gamerlegend

답변

0

날을 제공하는 컨트롤러 속성에 제약을 연결합니다. 그런 다음 제약 값을 변경하려면 self.myConstraint.constant = 0;. 또한 제약 조건 값을 변경 한 후보기에서 layoutIfNeeded으로 전화를 걸어 UIAnimation 안에서 수행하십시오.

가장 쉬운 방법으로 제약 조건을 관리 할 수 ​​있습니다.

+0

첫 번째보기 컨트롤러에서 프로그래밍 방식으로 secondview 컨트롤러를 제공하고 있는데이 제약 조건을 추가 할 위치는 어디입니까? – Gamerlegend

관련 문제