2008-09-25 7 views
1

UIScrollView에 각각 서브 뷰 세트가 있고이 하위 뷰 각각에 UITextView의 텍스트가 다른 경우가 있습니다. 이 작업을 위해 Apple을 스크롤보기의 하위보기를 생성하는 데 사용되는보기에 추가하기 위해 apple "iphone dev center"에서 PageControl 예제를 수정했습니다. (시뮬레이터와 전화 모두에서) 앱을 실행하면 아무 텍스트도 볼 수 없지만 "사용자 상호 작용"을 클릭하여 클릭하면 마술처럼 키보드가 나타납니다.UITextView의 텍스트가 UIScrollView에 표시되지 않습니다.

UIScrollView 안에 누구도 해결책이 있거나 UITextView으로 진행을 했습니까? 감사.

답변

2

나는이 문제가 UIScrollView의 하위 클래스이기 때문에 UIScrollViews 안에 포함 된 스크롤 뷰가 있다는 사실에 기인한다고 생각합니다. 텍스트가 제대로 표시 되더라도 핑거 스 와이프가 외부보기 또는 텍스트보기를 스크롤해야한다고 분명하지 않기 때문에 유용성 문제가 발생합니다.

그래, 사파리는 이런 일을하지만, 사파리를 사용하는 것이 가장 즐거운 부분은 아니다.

저는 이것이 어려움이 시스템에 대해 작업 중임을 나타내는 시간 중 하나라고 생각합니다. 돌아가서 UI를 다시 생각해 보는 것이 좋습니다.

+0

답해 주셔서 감사합니다. 또한 UITextView가 UIScrollView의 하위 클래스이기 때문에이 버그가 UIWebView에서도 발생하기 때문에 버그가 있다고 생각합니다. 그러나이 방법을 사용하면 시스템은 일련의 단계 또는 명령을 표시하는 자연스러운 방법이므로 – muesan

+1

동의하지만 버그라고 생각하지 않습니다. 기능입니다. 나는 애플이 이것을 피할 방법이 없다. –

-1

scrollViewDidScroll 메서드에 텍스트 값 할당을 지정하면 효과가 있습니다.

샘플 조각 :


는 sample.h

... 
@interface myRootUIViewController : UIViewController <UIScrollViewDelegate> 
... 

코멘트 : 그냥 유의 사항 : UIScrollViewDelegate 프로토콜을 잊지 마세요.


SAMPLE.m

- (void)viewDidLoad { 
     ... whatever is created before and/or after... 

     NSString * text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
          Nunc semper lacus quis erat. Cras sapien magna, porta non, 
          suscipit nec, egestas in, arcu. Maecenas sit amet est. 
          Quisque felis risus, tempor eu, dictum ac, volutpat id, 
          libero. Ut gravida, purus vitae interdum elementum, tortor 
          justo porttitor nisi, id rhoncus massa."; 

     // calculate the required frame height according to defined font size and 
     // given text 
     CGRect frame = CGRectMake(0.0, 500.0, self.view.bounds.size.width, 1000.0); 
     CGSize calcSize = [text sizeWithFont:[UIFont systemFontOfSize:13.0] 
       constrainedToSize:frame.size lineBreakMode: UILineBreakModeWordWrap]; 
       // for whatever reasons, contraintedToSize seem only be able to 
       // calculate an appropriate height if the input frame height is larger 
       // than required. Means: if your text requires height=250 and input 
       // frame height=100, then this method won't give you the expected 
       // result. 

     frame.size = calcSize; 
     frame.size.height += 0; // calcSize might be not pixel-precise, 
           // so add here additional padding pixels 
     UITextView * tmpTextView = [[UITextView alloc]initWithFrame:frame]; 

     // do whatever adjustments 
     tmpTextView.backgroundColor = [UIColor blueColor]; // show area explicitly (dev 
                  // purpose) 
     self.myTextView = tmpTextView; 
     self.myTextView.editable = NO; 
     self.myTextView.scrollEnabled = NO; 
     self.myTextView.multipleTouchEnabled = NO; 
     self.myTextView.userInteractionEnabled = NO; // pass on events to parentview 
     self.myTextView.font = [UIFont systemFontOfSize:13.0]; 
     [tmpTextView release]; 
     [self.scrollView addSubview:self.myTextView]; 
} 

... 

- (void)scrollViewDidScroll:(UIScrollView *)sender { 
    // for simplicity text is repeated again, of course it can be a member var/etc... 
    NSString * text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
          Nunc semper lacus quis erat. Cras sapien magna, porta non, 
          suscipit nec, egestas in, arcu. Maecenas sit amet est. 
          Quisque felis risus, tempor eu, dictum ac, volutpat id, 
          libero. Ut gravida, purus vitae interdum elementum, tortor 
          justo porttitor nisi, id rhoncus massa."; 
    self.myTextView.text = text; // assign value within this method and it is 
           // painted as expected. 
    } 

코멘트 : 나는 분명히 샘플 인 이름과 값을 사용하여 소스 코드를 조정 한

. 다행히도 오타가 없습니다. 그러나 코드에는 텍스트 값이 변경 될 수 있으므로 실제로 다른 프레임 크기가 필요할 경우를 대비하여 텍스트의 필수 프레임 높이 계산이 포함되어 있습니다.

scrollViewDidScroll 메서드에 실제 텍스트 값 할당을 배치하면 스크롤하는 동안 깜박 거리지 않고 저에게 도움이되었습니다 (지금까지는 iPhone 시뮬레이터에서만 테스트되었습니다).

희망이 있습니다. 물론 나는이 isuse를 해결하기위한 건설적인 피드백, 개선 제안 또는 다른 방법에 대해서도 개방되어 있습니다.

+0

ViewDidScroll 텍스트를 할당하는 것은 잘못된 일처럼 들립니다. –

0

문제는 다음 UIScrollViews 일 가능성이 큽니다.

나는 세 가지 솔루션이 있다고 생각 :

  • 활성화하고 다양한 컨트롤이 선택으로 userInteractionEnabled을 사용하지 않도록 설정합니다. 텍스트를 가정하고 정적
  • 자신의 뷰를 구현하고 오히려 UITextView에 의존하는 것보다의 drawRect 메시지의 텍스트를 직접 그릴 (UILabelUIScrollView의 서브 클래스가 아닌)를 UILabel 대신 UITextView (A)의를 사용합니다.
1

UITextView가 오프 스크린에서 화면 영역으로 스크롤 될 때 제대로 업데이트되지 않는 문제가 발생할 수 있습니다.

확인이 페이지의 "오프 스크린 UITextViews가 제대로 업데이트되지 않습니다"섹션 : 그들은 화면을 표시하기 시작 때 사용 Multiple Virtual Pages in a UIScrollView

이 솔루션은 스크롤 뷰의 다시 그리기를 강요하는 것이었다. 이것은 완전히 불편하지만 문제를 해결합니다.

textView.contentOffset = CGPointMake(0, 1); 
textView.contentOffset = CGPointMake(0, 0); 
7

는 나는 "가짜"스크롤을 강제로 문제가 해결
[scrollView setAutoresizesSubviews:NO]; 
0

이 문제에 대한 나의 해결책은 달랐다 :. 내가 오프에있는 UIScrollView의 재산 "자동 크기 파단"로 설정하면 그것은 단지 일