samvermette / SVPullToRefresh

Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.
http://samvermette.com/314
MIT License
4.82k stars 1.09k forks source link

Have a navigation bar, refresh will make the first message is hidden under the navigation bar #235

Open andi911 opened 9 years ago

liruqi commented 9 years ago

I got the same problem recently. You need to add action handler in - viewDidAppear method or after, as you can get correct scroll view contentInset then (after iOS7).

- addPullToRefreshWithActionHandler method record current scrollview contentInset as originalTopInset, originalBottomInset and reset to that contentInset after - stopAnimating.

sinabs commented 9 years ago
(void)viewDidLoad {
     UIEdgeInsets inset = UIEdgeInsetsMake(64, 0, 0, 0); //64 is navigation.height+20
     self.tableView.contentInset = inset;
     self.tableView.scrollIndicatorInsets = inset;
}
cohix commented 9 years ago

The workaround from @sinabs makes the position of the tableView correct AFTER the pullToRefresh is triggered, but the placement beforehand is still incorrect.

sinabs commented 9 years ago

try a again this.

(void)viewDidLoad {
     //UIEdgeInsets inset = UIEdgeInsetsMake(64, 0, 0, 0); //64 is navigation.height+20
     //self.tableView.contentInset = inset;
     //self.tableView.scrollIndicatorInsets = inset;
     [self.navigationController.navigationBar setTranslucent:NO];
}
neil-wu commented 9 years ago

as liruqi said, I put action handler in - viewDidAppear, and it works fine~

litt1e-p commented 8 years ago

this is my solution: in viewDidLoad add below codes and it woks fine

if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
        self.automaticallyAdjustsScrollViewInsets = NO;
        UIEdgeInsets insets                       = self.tableView.contentInset;
        insets.top                                = self.navigationController.navigationBar.bottom;
        self.tableView.contentInset               = insets;
        self.tableView.scrollIndicatorInsets      = insets;
    }