2011-11-17 2 views
4

보기의 맨 아래에 하나의 UITextView가 있습니다. 사용자가 동영상을 탭하면보기가 150 픽셀 위로 움직여야합니다. 내가 사용하고 있습니다 :UITextView 애니메이션보기 후 잘못된 내용 오프셋

- (void)textViewDidBeginEditing:(UITextView *)textView{ 

- (void)textViewDidEndEditing:(UITextView *)textView{ 

이 할 수 있습니다.

iOS5에서 정상적으로 작동합니다. 그러나 iOS 4.3에서는 뷰가 애니메이션으로 처리 될 때이 UITextView의 내용이 약간 픽셀 씩 올라갑니다.

스크린 샷 : 비슷한 문제가 있었다 http://cl.ly/1q3e0W2G1M000u1U3w1f

누군가?

코드 :

- (void)textViewDidBeginEditing:(UITextView *)textView{ 
    if([textView.text isEqualToString:@"Placeholder text"]){ 
     textView.text = @""; 
    } 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.3]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 150.0), self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
} 

- (void)textViewDidEndEditing:(UITextView *)textView{ 
    if([textView.text isEqualToString:@""]){ 
     textView.text = @"Placeholder text"; 
    } 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.3]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 150.0), self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations];  
} 

답변

4
당신은 당신 애니메이션 textViewDidBeginEditing 방법 및 후 호출 방법이 완료되면 텍스트보기의 내용 삽입을 다시 설정해야합니다

...

이 코드를보십시오 :

- (void)textViewDidBeginEditing:(UITextView *)textView{ 
    [textView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)]; 
} 
+0

이 코드를 어디에 넣어야합니까? – dormitkon

+0

감사합니다! 상수'UIEdgeInsetsZero'를 사용할 수도 있습니다. – colincameron

-3

이 문제를 해결하기 위해의 UITextField를 사용해보십시오.

+2

UITextFild는 여러 줄로 표시되지 않습니다. – dormitkon

3

내가 허용 대답이 발생하는 것을 발견 약간의 시각적 인 불규칙성. 다음은 나에게 훨씬 효과적이었다.

textView.contentMode = UIViewContentModeTop;