【问题标题】:Uitext Content SIze in UI Scroll View , the text in bottom is cut offUI Scroll View 中的 Text Content SIze ,底部的文本被截断
【发布时间】:2011-12-11 00:21:16
【问题描述】:

我有 UIScroll,里面有 uitextview。

我的应用如下所示:

rootviewcontroller -> PhoneContentController (UIScrollView 和 PageControl) -> DetailController (UITextView, UIWebView, UILabel)。

我的流程是这样的:

设置UIScrollView默认大小->调用DetailController(计算UITextView和其中的其他页面在viewDidLoad中)->PhoneContentController从DetailController获取总高度大小->改变高度UIScrollView

这是PhoneContentController(loadSCrollViewWithPage)中的代码:

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

详细控制器中的代码(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;

这个代码在DetailControllergetTotalHeight:

 CGRect cgRect = [[UIScreen mainScreen] bounds];

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

                       return scrollFrame;

我可以滚动滚动视图,但 textview 不能加载所有字符串。只喜欢它的一半,但我可以向下滚动但有空白页:(。

谁能帮帮我?

谢谢

【问题讨论】:

  • 能否请您尝试更详细地解释这句话,我不知道您期望会发生什么以及实际发生了什么:“我可以滚动滚动视图,但文本视图无法加载所有字符串. 只喜欢它的一半,但我可以向下滚动但有空白页:(。"

标签: iphone objective-c uiscrollview uitextview


【解决方案1】:

使用此函数设置滚动视图的内容大小。

-(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)];
}

将所有控件添加到滚动视图后,调用此函数并将yourScrollView 作为参数传递。希望这会对你有所帮助............

【讨论】:

    【解决方案2】:

    根据 Apple 的说法...当调试文本视图的问题时,请注意这个常见的陷阱:

    在滚动视图中放置一个文本视图。文本视图处理它们自己的滚动。您不应该在滚动视图中嵌入文本视图对象。如果这样做,可能会导致意外行为,因为这两个对象的触摸事件可能会混淆和错误处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-11
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 2019-11-14
      • 2015-06-02
      • 2020-06-11
      • 1970-01-01
      相关资源
      最近更新 更多