2011-02-25 5 views
0

나는 아주 이상한 행동을 봅니다. 스크롤 뷰의 일부인보기 안에 텍스트보기가 표시됩니다. 텍스트보기에서 타이핑을 시작하면 키보드는 일반적으로 텍스트보기를 숨긴 다음 텍스트보기에 애니메이션을 적용하고 키보드 위에 밀어서 보이도록합니다. 그렇게하면 입력 한 텍스트를 볼 수있는 순간 키보드를 닫을 때까지 입력 한 세 번째 및 후속 행이 보이지 않습니다. 텍스트보기에서 타이핑을 시작하면 키보드를 숨기지 않기 때문에 움직이기 위해 애니메이션을 할 필요가 없습니다. 그런 다음 입력 한 모든 텍스트를 볼 수 있습니다. 따라서 텍스트가 나타날 때만 문제가 발생합니다. 보기 애니메이션입니다. 하지만 함께입력하는 동안 UITextView 텍스트 숨기기

- (void) makeTextViewVisible: (UITextView *)textArea up:(BOOL) up { 

if (up) { 
    animatedDistance = 0; 

    CGPoint myPoint = [textArea.superview convertPoint:textArea.frame.origin toView:[UIApplication sharedApplication].keyWindow]; 

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
    if (orientation == UIInterfaceOrientationPortrait) { 
     animatedDistance = PORTRAIT_KEYBOARD_HEIGHT - (950 - myPoint.y) + 150; 
    } 
    else if (orientation == UIInterfaceOrientationPortraitUpsideDown) { 
     animatedDistance = PORTRAIT_KEYBOARD_HEIGHT + (PORTRAIT_KEYBOARD_HEIGHT - myPoint.y); 
    } 
    else if (orientation == UIInterfaceOrientationLandscapeLeft) { 
     animatedDistance = myPoint.x - LANDSCAPE_KEYBOARD_HEIGHT + 120; 
    } 
    else if (orientation == UIInterfaceOrientationLandscapeRight) { 
     animatedDistance = LANDSCAPE_KEYBOARD_HEIGHT - myPoint.x + 100; 
    } 

    if (animatedDistance < 0) { 
     animatedDistance = 0.0; 
    } 

    CGRect viewFrame = textArea.frame; 
    viewFrame.origin.y -= animatedDistance; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; 

    [textArea setFrame:viewFrame]; 

    [UIView commitAnimations]; 

} 
else { 
    CGRect viewFrame = textArea.frame; 
    viewFrame.origin.y += animatedDistance; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; 

    [textArea setFrame:viewFrame]; 

    [UIView commitAnimations];  
} 

내가 textViewDidChange 내부 setNeedsDisplay/setNeedsLayout를 호출 시도 : 아래

self.textView = [[UITextView alloc] initWithFrame:CGRectMake(...)]; 
    textView.font = [UIFont systemFontOfSize:18.0]; 
    textView.backgroundColor = [UIColor whiteColor]; 
    textView.userInteractionEnabled = YES; 
    textView.clipsToBounds = YES; 
    textView.delegate = self; 
    textView.layer.borderWidth = 1; 
    textView.layer.borderColor = [[UIColor blackColor] CGColor]; 
    textView.layer.cornerRadius = 10; 
    [self addSubview:textView]; 
    [textView release]; 

텍스트 뷰를 애니메이션 코드입니다 : 아래

텍스트 뷰를 작성 내 코드입니다 운.

누구나이 문제가 발생했거나 해결 방법을 알고 있습니까?

감사합니다.

답변

1

몇 가지 생각을하십시오. 먼저, 당신은 animatedDistance 계산으로 너무 열심히 일하고 있다고 생각합니다. 일반적으로 UIWindow의 크기 (장치와 함께 회전하지 않음)로 작업하는 대신 마스터보기를 만듭니다. 그렇지 않은 경우에는 상태 표시 줄, 전화 상태 표시 줄 등을 고려해야합니다.보기를 사용하면 두 가지 키보드 높이를 모두 보정하여 모든 계산을 하나로 줄일 수 있습니다 :

if ((orientation == UIInterfaceOrientationLandscapeLeft)|| (orientation == UIInterfaceOrientationLandscapeRight)) { 
    keyboardHeight = LANDSCAPE_KEYBOARD_HEIGHT; 
} else { 
    keyBoardHeight = PORTRAIT_KEYBOARD_HEIGHT; 
} 

CGPoint myPoint = [self.view convertPoint:textArea.frame.origin toView:self.view]; 
float windowHeight = self.view.bounds.size.height; 

animatedDistance = myPoint.y+textArea.bounds.size.height+keyboardHeight-windowHeight; 

if (animatedDistance < 0) { 
    animatedDistance = 0.0; 
} 

보기의 경계를 사용하면 필요한 정보를 얻을 수 있습니다.

둘째, 왜 textView를 움직입니까? 스크롤 창에서 scrollPos를 조정하는 것만으로도 되겠습니까?

세 번째로 scrollview 내부에있는 뷰 내부에있는 textView를 참조합니다 (코드에는 표시되지 않지만). 중간 뷰의 경계에 의해 textView가 잘릴 수 있으므로 결과를 볼 수는 없지만 입력 할 수는 있습니다. textView의 경계를 볼 수 있습니까?

마지막으로, 미적 포인트 인 animatedDistance는 상태 변수이므로 애니메이션을 다시 넣은 후 else 분기에서 animatedDistance를 0으로 설정해야합니다. 그런 식으로 makeTextViewVisible : textView UP : false를 두 번 호출하면 아무렇지도 않게됩니다.

+0

매우 유용한 점. 나는 스크롤 위치를 조정하는 두 번째 아이디어를 좋아한다. –

관련 문제