简体   繁体   中英

ScrollsToTop feature is not working in iOS9 properly

I have a UIViewController having a UITableView with large data. I want to implement the feature of scrolltotop on press of the statusbar.

I have a lot of UIView set through my storyboard so I first try to set scrollsToTop = NO for all and then set the scrollsToTop = YES for the UITableView specifically in viewDidLoad .

The same settings/configuration works with iOS8 but not with iOS9 .

I have applied below code to disable scroll for all subviews in start:

- (void)disableScrollsToTopPropertyOnAllSubviewsOf:(UIView *)view {

    for (UIView *subview in view.subviews) {
        if ([subview isKindOfClass:[UIScrollView class]]) {
            ((UIScrollView *)subview).scrollsToTop = NO;
        }
        [self disableScrollsToTopPropertyOnAllSubviewsOf:subview];
    }
}

尝试使用内容偏移量

self.tableView.contentOffset = CGPointMake(0, 0 - self.tableView.contentInset.top);

Make sure you call it on viewDidAppear :

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    // Call scroll to top here
}

I hope this can help.

幸运的是,这开始在iOS 10.0中完美运行

You might have more than one UIScrollView in your view hierarchy, and you have to set only the one you want to scroll to top to Yes and the others scrollsToTop = No; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM