2015-01-01 3 views
0

앱에 대한 설명 입력 컨트롤을 구축하고 있습니다. 이 컨트롤은 UIView에 포함 된 UITextView으로 구성됩니다. 모든 제약 조건은 프로그래밍 방식으로 처리됩니다. 사용자가 UITextView을 탭하면 키보드가 열립니다. 그러면 키보드 옵저버 메서드가 호출되고 키보드로 위로 이동하기 위해 주석 입력 컨트롤의 아래쪽 제약 조건을 조정합니다. 그러나 사용자가 입력 할 공간이 더 많아 지도록 동시에 입력 컨트롤의 높이를 높이려고합니다. 이 문제를 해결하는 데 어려움이 있습니다.키보드보기가있을 때 UIView 프로그래밍 제약 높이가 증가합니다.

-(void)updateViewConstraints 
{ 

    NSDictionary *views = @{ 
          @"table"   : self.commentsTableView, 
          @"seeMoreComments" : self.seeMoreCommentsView, 
          @"commentInput" : self.commentEntryInput 
          }; 

    //See More Comments Constraints 
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[seeMoreComments]-0-|" options:0 metrics:nil views:views]]; 
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[seeMoreComments(45)]" options:0 metrics:nil views:views]]; 

    //Table view constraints 
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[table]-0-|" options:0 metrics:nil views:views]]; 
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[seeMoreComments]-0-[table]-0-|" options:0 metrics:nil views:views]]; 

    //Comment entry input 
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[commentInput]-0-|" options:0 metrics:nil views:views]]; 

    commentInputVerticalConstraint = [NSLayoutConstraint constraintWithItem:self.commentEntryInput 
                   attribute:NSLayoutAttributeHeight 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:nil 
                   attribute:NSLayoutAttributeHeight 
                   multiplier:1.0 
                   constant:commentInputHeight]; 

    if(commentInputBottomConstraint == nil) 
    { 
    commentInputBottomConstraint = 
    [NSLayoutConstraint constraintWithItem:self.commentEntryInput 
           attribute:NSLayoutAttributeBottom 
           relatedBy:NSLayoutRelationEqual 
            toItem:self.view 
           attribute:NSLayoutAttributeBottom multiplier:1.0 
            constant:0.0]; 

    } 

    [self.view addConstraint:commentInputVerticalConstraint]; 
    [self.view addConstraint:commentInputBottomConstraint]; 

    [super updateViewConstraints]; 
} 

이제 keyBoardWillShow을 호출 할 때 호출되는 메서드가 있습니다. 이 메서드는 키보드가 나타날 때 주석 입력 컨트롤을 애니메이션으로 나타냅니다. 그러나

(void)animateContentWithKeyboardInfo:(NSDictionary *)keyboardInfo 
    { 
     NSNumber    *animationDuration = keyboardInfo[ UIKeyboardAnimationDurationUserInfoKey ]; 
     NSValue     *keyboardFrameValue = keyboardInfo[ UIKeyboardFrameEndUserInfoKey ]; 
     CGRect     keyboardFrame  = [keyboardFrameValue CGRectValue]; 
     UIViewAnimationCurve animationCurve  = [keyboardInfo[ UIKeyboardAnimationCurveUserInfoKey ] intValue]; 

     UIViewAnimationOptions animationOptions = animationOptionWithCurve(animationCurve); 

     commentInputBottomConstraint.constant = (keyboardFrame.origin.y - [UIScreen mainScreen].bounds.size.height); 

     //Increase the veritcal height of the comment input control 
     commentInputVerticalConstraint.constant = 125; 

     //Takes into account that the Tab Bar is 50 points, and adjust for this 
     //value. 

     if(keyboardAppeared == YES) 
     { 
     commentInputBottomConstraint.constant += TAB_BAR_OFFSET; 
     } 

     else 
     { 
     commentInputBottomConstraint.constant -= TAB_BAR_OFFSET; 
     } 

     [self.view layoutIfNeeded]; 

     [self.view setNeedsUpdateConstraints]; 

     [UIView animateWithDuration:[animationDuration floatValue] delay:0.0 options:animationOptions animations: 
     ^{ 


     [self.view layoutIfNeeded]; 

     } completion:nil]; 
    } 

, 내가이 오류 메시지가 나타납니다 commentInputVerticalConstraint의의 지속적인 조정을 시도 : 날 "재설정"할 수있는 방법이 있는지

Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the `UIView` property `translatesAutoresizingMaskIntoConstraints`) 
(
    "<NSLayoutConstraint:0x1899fcb0 V:[CommentEntryInput:0x176e5160(50)]>", 
    "<NSLayoutConstraint:0x1899e5c0 V:[CommentEntryInput:0x176e5160(125)]>" 
) 

잘 모르겠어요를 또는 키보드가 나타나면 처리 할 제약 조건을 조정 한 다음 키보드가 사라지면 다시 정상으로 되돌립니다. 어떤 도움을 주시면 감사하겠습니다.

답변

1

-(void)updateViewConstraints이 두 번 이상 호출되는 문제가 있습니다. 따라서 새로운 제약 조건을 생성하고이를 뷰에 두 번 추가하는 것입니다. 제약 조건이 nil인지 아닌지 확인해보십시오.

정수의 애니메이션이 변경되기 전에 먼저 [self.view layoutIfNeeded]이 필요하다고 생각하지 않습니다. 상수를 변경할 때 그냥 설정 한 다음 애니메이션 블록에 [self.view layoutIfNeeded]을 래핑하여 새 값에 애니메이션을 적용합니다.

관련 문제