在viewWillAppear中添加UIScrollView时会被剪裁

时间:2014-05-26 18:40:43

标签: ios uiscrollview

我有一个UIScrollView的子类,我正在尝试将它添加到我的视图中。出于某种原因,当我在viewDidLoad中添加它时,它按预期工作。但是当我尝试在viewWillAppear中添加它时,它似乎更改了contentSize(尽管当我打印contentSize时,它在任何一种情况下都是905)

这可以按预期工作:

- (void)viewDidLoad
{
    [super viewDidLoad];
    diptic = [[DipticView alloc] initWithFrame:self.view.frame];
    diptic.item = self.item;
    [self.view addSubview:diptic];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

enter image description here

这会切断scrollView(两个视图都一直向下滚动。)

- (void)viewDidLoad
{
    [super viewDidLoad];
    diptic = [[DipticView alloc] initWithFrame:self.view.frame];
    diptic.item = self.item;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.view addSubview:diptic];
}

enter image description here

关于为什么会发生这种情况的任何想法?

编辑:  我认为框架正在某处重置,因为如果我这样做:

diptic = [[DipticView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];

我得到了相同的结果......

0 个答案:

没有答案