[英]Scroll view with Auto Layout
I have a view in scrolling view, and when I seque(push) from this ViewController to CommentViewController, and came back, view in scroll view moved for 200 px up, I dont know why, I don`t anything in code. 我在滚动视图中有一个视图,当我从该ViewController插入(推入)到CommentViewController并返回时,滚动视图中的视图向上移动了200 px,我不知道为什么,我在代码中什么都没有。
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 2000)];
}
Its when Auto Layout is on. 启用“自动布局”时。 When it off, its work, but design is not impressive... Can I fix it with Auto Layout?
当它关闭时,它可以工作,但设计效果不佳...我可以使用“自动布局”修复它吗?
Here's a quick fix 这是一个快速修复
In viewWillDisappear, save the scrollView's contentOffset and reset it to zero. 在viewWillDisappear中,保存scrollView的contentOffset并将其重置为零。
Later in viewDidLayoutSubview, restore the contentOffset to old value. 稍后在viewDidLayoutSubview中,将contentOffset恢复为旧值。
Here's the sample code 这是示例代码
-(void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if(!CGPointEqualToPoint(CGPointZero, self.contentOffset))
{
scroller.contentOffset = self.contentOffset;
self.contentOffset = CGPointZero;
}
}
-(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.contentOffset = scroller.contentOffset;
scroller.contentOffset = CGPointZero;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.