Programing

UIScrollView 내부에있는 UITextView에서 큰 텍스트가 잘림

lottogame 2020. 12. 28. 07:43
반응형

UIScrollView 내부에있는 UITextView에서 큰 텍스트가 잘림


나는 내가 고칠 수없는 심각한 문제를 겪고 있으며 지난 이틀 동안 나를 미치게 만든다. 멀리서 찾아 봤는데 많은 시도를했지만 해결책을 찾을 수 없습니다.

나는이 UITextView내부 a를 UIScrollView. UITextView텍스트를 표시하기 위해 scrollview 내부의 크기를 동적으로 조정할 수 있습니다. 그러나 UITextView에 매우 큰 텍스트 포함 된 경우 거의 끝까지 스크롤하면 잘립니다. 그러나 UIScrollView의 프레임은 여전히 ​​올바른 크기입니다.

: 나는이 게시물 읽기 많은 유사한 것들.

UIScrollview하고는 UITextview모두 자동 레이아웃을 사용하여 XIB에서 생성됩니다.

다음은 현재 코드와 스크린 샷입니다. 스크린 샷의 빈 부분이 텍스트로 채워 져야합니다. 도와주세요.

여기에 이미지 설명 입력

- (void)viewDidAppear:(BOOL)animated
{
    CGRect frame = self.longDescField.frame;
    frame.size.height = self.longDescField.contentSize.height;
    self.longDescField.frame = frame;

    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width,  self.longDescField.contentSize.height + 200);
    self.scrollView.scrollEnabled = YES;
    [self.scrollView flashScrollIndicators];
}

이 문제는 iOS 7부터 존재했으며 iOS 12에도 여전히 존재합니다.

그러나 scrollEnabled = NO@igz가 권장하는 것처럼 크기 조정 전에 설정하여 정상적인 스크롤 동작을 유지할 수 없었습니다 . 대신에 나는 스크롤 전환 onoff크기 조정 후

// Resize text view here

textView.scrollEnabled = NO;
textView.scrollEnabled = YES;

이로 인해 잘린 텍스트가 올바르게 렌더링되었습니다.


여러분의 도움에 감사드립니다. 이것은 궁극적으로 iOS7에서 나를 위해 일하게 된 것입니다.

이 특정 xib에 대해 자동 레이아웃비활성화 해야했습니다 .

그런 다음 다음을 수행했습니다.

[textView setScrollEnabled:YES];
[textView setText:text];
[textView sizeToFit];
[textView setScrollEnabled:NO];

나에게 해결책은 sizeToFittextView를 사용자 정의 한 후

[self.yourTextView sizeToFit];

이것은 textview를 조작 할 때 마지막으로해야하는 일이어야하며 콘텐츠 텍스트를 채우기 전에는 안됩니다.


확실히 iOS7. 크기가 조정 된 모든 UITextView (xib 및 코드 생성)에 동일한 문제가 적용되었습니다. UITextView 프레임이 변경된 후 조정이 필요한 textContainer.size를 찾았습니다.

textContainer.size를 조정하기 위해이 카테고리 코드를 만들었지 만 텍스트 값을 설정 한 후에도 조정이 필요한 것 같아서 프레임 크기를 설정하지 않으면 텍스트가 변경된 후 adjustAfterFrameChange를 호출해야합니다. 이 코드는 UITextView가 setFrame : 자체로 아무 작업도하지 않는다고 가정하므로 setFrame :을 제거하고 해당 위험을 피하려면 수동으로 adjustAfterFrameChange를 호출하십시오.

편집 : 변경

self.textContainer.size = self.frame.size; // fix for cut off text

...에

self.textContainer.size = self.contentSize; // fix for cut off text

@interface UITextView(Extras)

- (void)adjustAfterFrameChange;

@end



@implementation UITextView(Extras)

- (void)adjustAfterFrameChange {
#if defined(__IPHONE_7_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
    if ([self respondsToSelector:@selector(textContainer)])
        self.textContainer.size = self.contentSize; // fix for cut off text
#endif
}


- (void)setFrame:(CGRect)frame {
    [super setFrame:frame];

    [self adjustAfterFrameChange];
}

@end

이 시도

[self.textView setContentInset:UIEdgeInsetsMake(-8.0, 0, -8.0, 0)];

UITextView에서 잘린 텍스트 표시에 대해 작동합니다.


I had a similar issue, wherein long text was getting cut off after a resize of the text view. Turning off scrollingEnabled before the resize seemed to fix it. Sure seems like an IOS 7 bug.


This issue can be fixed by setting the contiguous layout property to false.

textView.layoutManager.allowsNonContiguousLayout = false

Although the documentation says that the default value is false, it is actually set to true for a UITextView.


We had the same problem, except the left half or right half of the UITextView was getting cut off. Happened on both iOS 7 and iOS 6, on a variety of phones. Calling:

myTextView.scrollEnabled = NO;

in viewWillAppear worked around the problem.


Just try this.

In IOS 8 and Xcode 6.3,

textview.scrollEnabled=YES;
[self.textview setContentInset:UIEdgeInsetsMake(-10.0, 0, -5.0, 0)];

We had an issue like this with the rollout of iOS7. When we called setText which added a new line (or lines) to our UITextView, the textview wasn't using the correct new height for its redrawing. The setNeedsDisplay, setNeedsLayout, redrawing layers, redrawing the entire view, etc all didn't work. Finally we forced a loss and gain of focus:

[textView resignFirstResponder];
[textView becomeFirstResponder];

This forced the height recalculation and correct redraw. Thankfully it does not cause the keyboard to pop out and in, but it's worth regression testing that on any iOS versions your app supports.


This happens all the way, from in Interface Builder too.

When text view selected, in Utilities Inspector uncheck the option Shows Vertical Indicator. The cropped text appears now.


None of these answers worked for me.

I was fooling with the storyboard and somehow it's working now. It still looks wrong in the storyboard but on the device it's now displaying fine.

I did various things, including toggling many of the options for the textfield.

I think what fixed it for me was making the view larger, building, and making it the right size again.

My apologies for a vague uncertain answer, but maybe it helps. This project was originally written for iOS 5, and the text view may not have been messed with much since then.


I have the same Problem for a textview (without a scrollview). Solved this (Xcode 7.3.1, iOS 9.3) just by unchecking "Scrolling Enabled" in the Attributes Inspector.


내가 틀렸을 수도 있지만 문제를 철저히 이해하지는 못하지만 UITextView 클래스가 스크롤 가능한 여러 줄 텍스트 영역에 대한 동작을 구현하기 때문에 UIScrollView를 사용하는 용도는 무엇입니까?

UIScrollView를 삭제해야합니다.


저도 같은 상황에 직면 해 있습니다. UITextView의 스크롤을 비활성화해야하고 마지막 줄이 잘립니다. 내 해결책은 다음과 같습니다.

//In the  UITextView subClass, override "gestureRecognizerShouldBegin" and let the scrolling of UITextView remain on.

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && gestureRecognizer.view == self){
        return NO;
    }
    return [super gestureRecognizerShouldBegin:gestureRecognizer];
}

스위프트에서 나는 간단하게 설정하여이 문제를 해결 textContainerInset내의를 UITextView:

textView.textContainerInset = UIEdgeInsets(top: 0.0, left: 0.0,
                                           bottom: 50.0, right: 0.0)

참조 URL : https://stackoverflow.com/questions/18696706/large-text-being-cut-off-in-uitextview-that-is-inside-uiscrollview

반응형