UIScrollView scroll not working after pushed with a navigation controller

戏子无情 提交于 2019-12-02 06:15:52

问题


I'm having an odd problem. I have a UIScrollView in a part of view hierarchy. It's working just fine when the view is presented via UITabBarController, but doesn't work at all after it is pushed with a Navigation controller (it is the third vc pushed atop the root). The scroll view was created in storyboard and the following lines are in the viewDidAppear method:

[super viewDidAppear:animated];
[self.scrollView setScrollEnabled:YES];
self.scrollView.contentSize = CGSizeMake(320.0f, 468.0f);

Any ideas, or suggestions? If you need shots of scrollview attributes inspector let me know. Here's the call method. The error might be somewhere inside here.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone"
                                                 bundle:nil];
    MKontaktViewController *vc = [sb instantiateViewControllerWithIdentifier:@"Kontakt"];
    vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self.navigationController pushViewController:vc
                                         animated:YES];

Thanks, Churchill


回答1:


If you resize the scroll view content size in the viewDidLayoutSubview function it will work again.

- (void) viewDidLayoutSubviews {
    [self resizeScrollViewContent];
}

and
here same question




回答2:


I've solved this problem, but forgot to post it...

    - (void) viewDidLayoutSubviews 
    {
        [self resizeScrollViewContent];
    }

    - (void) resizeScrollViewContent
    {
        self.scrollView.contentSize = CGSizeMake(320.0f, 468.0f);
    }

Or you could use this as well:

    - (void) viewDidLayoutSubviews 
    {
        self.scrollView.contentSize = CGSizeMake(320.0f, 468.0f);
    }


来源:https://stackoverflow.com/questions/22831968/uiscrollview-scroll-not-working-after-pushed-with-a-navigation-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!