Uitext Content SIze in UI Scroll View , the text i

2019-07-01 15:41发布

问题:

I have UIScroll that have uitextview inside it.

My apps look like this:

rootviewcontroller -> PhoneContentController (UIScrollView and PageControl) -> DetailController (UITextView, UIWebView, UILabel).

My Flow is like this:

Set UIScrollView default size -> call DetailController (calculate UITextView and other page inside it in viewDidLoad) -> PhoneContentController get the total height size from DetailController-> Change the height of UIScrollView

This is the code in PhoneContentController (loadSCrollViewWithPage):

scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, [detailController.getTotalHeight]);

The code in Detail Controller (viewDidLoad):

summaryBlogParsed = [summaryBlogParsed stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[self.itemSummaryText setText:summaryBlogParsed];

CGRect frameTextView = self.itemSummaryText.frame;    

frameTextView.size.height = self.itemSummaryText.contentSize.height;

self.itemSummaryText.frame = frameTextView;

This code in DetailController getTotalHeight:

 CGRect cgRect = [[UIScreen mainScreen] bounds];

CGFloat scrollFrame = (cgRect.size.height/2) + itemSummaryText.frame.size.height;

                       return scrollFrame;

I can scroll the scrollview but the textview not load all of the string. like only half of it, but i can scroll down but with blank pages :(.

Anyone can help me?

Thank you

回答1:

set content size of scroll view using this function.

-(void)setContentSizeOfScrollView:(UIScrollView*)scroll
{
    CGRect rect = CGRectZero;

    for(UIView * vv in [scroll subviews])
    {
        rect = CGRectUnion(rect, vv.frame);
    }

    [scroll setContentSize:CGSizeMake(rect.size.width, rect.size.height)];
}

after adding all controls to your scroll view call this function and pass yourScrollView as argument. Hope this will help you.........



回答2:

According to Apple... When debugging issues with text views, watch for this common pitfall:

Placing a text view inside of a scroll view. Text views handle their own scrolling. You should not embed text view objects in scroll views. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.