【问题标题】:Scroll the page in iPhone view在 iPhone 视图中滚动页面
【发布时间】:2012-07-01 11:50:54
【问题描述】:

我有一个视图,其中包含某些事件的详细信息,包括图像视图、一些标签等。 我将事件描述为视图中的一个小子视图,如下所示。

CGRect descriptionTextViewRect = CGRectMake(15, 185, 280, 85);
descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect];
descriptionText.textAlignment = UITextAlignmentLeft;
descriptionText.text =des;
descriptionText.editable = NO;
descriptionText.layer.cornerRadius = 5.0;
descriptionText.clipsToBounds = YES;
descriptionText.userInteractionEnabled = YES;
descriptionText.font = [UIFont systemFontOfSize:15];
[scrollView addSubview: descriptionText];

我关注了这个link,但我可以在文本视图和滚动视图中滚动

我是这样关注的

float sizeOfContent = 0;
 int i ;

for (i=0; i<[scrollView.subviews count]; i++) {
    sizeOfContent += descriptionText.frame.size.height;
}

scrollView.contentSize = CGSizeMake(descriptionText.frame.size.width, sizeOfContent)

我需要显示描述的全部内容并使整个详细页面可滚动。

我做得对吗?还是我错过了什么?

我该怎么做?

谢谢。

【问题讨论】:

    标签: objective-c ios ios5 ios4


    【解决方案1】:

    您正在多次添加相同项目的高度。

    这个:

    for (i=0; i<[scrollView.subviews count]; i++) {
        sizeOfContent += descriptionText.frame.size.height;
    }
    

    应该是这样的:

    for (UIView *view in scrollView.subviews) {
        sizeOfContent += view.frame.size.height;
    }
    

    所以它会正确地将所有项目的高度添加到sizeOfContent

    【讨论】:

    • 完全正确,但我需要设置描述文本的大小并使详细信息页面可滚动。我现在只能滚动描述文本。请您对此提出建议吗?
    【解决方案2】:

    您每次都在同一位置添加子视图。例如:如果您要添加 5 个子视图,则应如下所示:

    for(int i=0; i<5; i++)
    {
    CGRect descriptionTextViewRect = CGRectMake(15, i*185, 280, 85);
    descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect];
    descriptionText.textAlignment = UITextAlignmentLeft;
    descriptionText.text =des;
    descriptionText.editable = NO;
    descriptionText.layer.cornerRadius = 5.0;
    descriptionText.clipsToBounds = YES;
    descriptionText.userInteractionEnabled = YES;
    descriptionText.font = [UIFont systemFontOfSize:15];
    [scrollView addSubview: descriptionText];
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多