UIScrollview Autolayout Issue

2019-01-13 20:29发布

I have a problem with autolayout(maybe) and my scrollview!

My Problem

  1. I scroll down View

2.Then I push to another View

3.Then I go back and the scrollview looks like that and I'm not able to scroll to the highest point.(I see it in the bouncing of the scrollview) Scrollview

Can anybody help me?

9条回答
霸刀☆藐视天下
2楼-- · 2019-01-13 21:10

I use an UITabBarController and different views with auto layout. The views are longer than the screen of the device. Switching from one tab to the other lead sometimes to the problem you describe. This only happened if the view has been scrolled down before the switch. I tried all the advice here but this did not work for my case. My solution was to scroll up again before leaving the view. At least a work around for this bug in iOS 6:

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [scrollView setContentOffset:CGPointZero animated:NO];
}
查看更多
乱世女痞
3楼-- · 2019-01-13 21:11

if you are still searching for an answer i found it today after two days of headbanging the wall. I will just paste you the code, but the most important thing is when you load your scrollView..

    -(void)viewWillAppear:(BOOL)animated{

    [scrollView setFrame:CGRectMake(0, 0, 320, 800)];
}

-(void)viewDidAppear:(BOOL)animated
{
    [scrollView setScrollEnabled:YES];
    [scrollView setContentSize:CGSizeMake(320, 800)];

}

all this is loaded before -(void)viewDidLoad

notice the height is in both instances 800, which is crucial for resolving this problem. good luck with your project ;)

查看更多
Root(大扎)
4楼-- · 2019-01-13 21:12

have you tried this?

self.automaticallyAdjustsScrollViewInsets = NO;

In my case this was what solved my problem.

查看更多
登录 后发表回答