Uitext Content SIze in UI Scroll View , the text in bottom is cut off

雨燕双飞 提交于 2019-12-10 21:22:42

问题


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.



来源:https://stackoverflow.com/questions/7823229/uitext-content-size-in-ui-scroll-view-the-text-in-bottom-is-cut-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!