0

I am quite new to iOS application development.

I was working with UIScrollView and found very strange behavior. Hope somebody could explain this to me.

I tried the two methods and found the outputs different.

1). UIScrollView is added to my view in the Interface Builder, and a view (UIView) is also added to the scrollview earlier. I set the view's bounds manually in the IB, and set the scrollview's content size in the class file.

Observation : The scrollview doesn't scroll with the setcontentsize, rather takes some unusual content size, independent of anything else, even its own bounds.

2). The same UIScrollView is again added in the Interface Builder, but the view is added this time programmatically.

Observation : This time everything works out quite good.

I don't understand what could have gone wrong.

Can anyone explain and elaborate

4

1 回答 1

0

我不确定您的问题到底是什么,但是如果您希望能够在 IB 中向 UIScrollView 添加视图,请创建一个 UIScrollView 子类并执行以下操作:

- (void)awakeFromNib
{
    [super awakeFromNib];

    CGRect bounds = CGRectZero;

    for (UIView* view in self.subviews)
    {
        bounds = CGRectUnion(bounds, view.frame);
    }

    [self setContentSize:bounds.size];
}
于 2013-04-05T10:01:11.127 回答