2014-11-12 2 views
-2

나는 이렇게 열고 닫는 채팅을했습니다.키보드가 자동 레이아웃에서 변경 한 내용을 되돌릴 수 없게하는 방법은 무엇입니까?

-(IBAction)visaChat:(id)sender{ 

    if(chatOpen2==0){ 

     chatOpen2=1; 

     [UIView animateWithDuration:0.5 animations:^{ 
      chatView.center = chatView2.center; //x,y 
      [self.view layoutIfNeeded]; // Called on parent view 
     }]; 
    } 
    else{ 

     chatOpen2=0; 

     [UIView animateWithDuration:0.5 animations:^{ 
      chatView.center = chatView3.center; //x,y 
      [self.view layoutIfNeeded]; // Called on parent view 
     }]; 
    } 
} 

chatView 내부에는 UITextField가 있습니다.

textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 40, 210, 40)]; 
[textField setReturnKeyType: UIReturnKeySend]; 
textField.borderStyle = UITextBorderStyleRoundedRect; 
textField.font = [UIFont systemFontOfSize:15]; 
textField.placeholder = @"Meddelande"; 
textField.autocorrectionType = UITextAutocorrectionTypeNo; 
textField.keyboardType = UIKeyboardTypeDefault; 
textField.clearButtonMode = UITextFieldViewModeWhileEditing; 
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
textField.delegate = self; 
[textField.layer setBorderWidth:1]; 
[textField.layer setCornerRadius:4]; 
[textField.layer setBorderColor:[[UIColor colorWithRed:(0/255.0) green:(0/255.0) blue:(0/255.0) alpha:0.5] CGColor]]; 
[[textField layer] setMasksToBounds:YES]; 
[textField addTarget:self 
       action:@selector(textFieldDidChange:) 
    forControlEvents:UIControlEventEditingChanged]; 
textField.enabled=YES; 
textField.userInteractionEnabled=YES; 
textField.multipleTouchEnabled=YES; 
[chatView addSubview:textField]; 

자동 레이아웃을 구현 한 이래로 chatView는 텍스트 필드를 클릭 할 때 (visaChat이 호출되지 않고) 자동으로 닫힙니다. 즉, 애니메이션에서 수행 된 모든 변경 사항을 취소 할 수 있습니다.

전화를 걸어서 자동으로 다시 열 수 있습니다.

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    [self.view layoutIfNeeded]; // Called on parent view 
    chatView.center = chatView2.center; //x,y 
    [self.view layoutIfNeeded]; // Called on parent view 
} 

그러나 이로 인해 키보드 열기 (및보기 자동 닫기)와보기 열기 사이에 간격이 생깁니다.

해결 방법?

답변

0

나는 뭔가를 발견했습니다.

나는 제약

IBOutlet NSLayoutConstraint *chatViewCenterXConstraint; 

을 위해 함께 IBOutlet을 생성 그리고

[self.view layoutIfNeeded]; // Called on parent view 
chatViewCenterXConstraint.constant = -220.0; 

[UIView animateWithDuration:0.5 animations:^{ 

    [self.view layoutIfNeeded]; // Called on parent view 
}]; 
를 넣어
관련 문제