Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contentInset not suitable with iOS7 #147

Open
cookingios opened this issue Sep 15, 2013 · 24 comments
Open

contentInset not suitable with iOS7 #147

cookingios opened this issue Sep 15, 2013 · 24 comments

Comments

@cookingios
Copy link

contentInset not suitable with iOS7

@kyo9999
Copy link

kyo9999 commented Sep 15, 2013

ios7 have problem too, do you change it?

@bassrock
Copy link

same problem here? any ideas to fix this properly?

@kyo9999
Copy link

kyo9999 commented Sep 16, 2013

i fix it like this:
-(void)viewDidAppear:(BOOL)animated
{
// setup the pull-to-refresh view
__weak UITableView *weaktableview = MyUITableView;
[self.MyUITableView addPullToRefreshWithActionHandler:^{
NSLog(@"refresh dataSource");
//[_AppDelegate.coreDataController iCloudAccountChanged:nil];
[weaktableview.pullToRefreshView performSelector:@selector(stopAnimating) withObject:nil afterDelay:1];
}];

@fanyj
Copy link

fanyj commented Sep 16, 2013

I test it with iOS7. It seems the work around by @kyo9999 can fix this problem. The problem was caused by iOS7 automaticallyAdjustsScrollViewInsets property. The default value of this property is YES. Simply disable it like this can also fix this problem. Remeber to check ios version if your need to support earlier ios version.

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.automaticallyAdjustsScrollViewInsets = NO;
    // Some other code...
}

@siburb
Copy link

siburb commented Sep 20, 2013

Beautiful! Thanks @fanyj, I wasn't looking forward to debugging that one!

@GaetanJuvin
Copy link

Nice @fanyj :-)

@sqlumee
Copy link

sqlumee commented Sep 22, 2013

It just work for the first time, but after the first pull the contentInset is broken again

@siburb
Copy link

siburb commented Sep 23, 2013

Strange - I'm finding the opposite. I was only ever having the problem on the first pull prior to this fix, and now I don't have it at all.

@fanyj
Copy link

fanyj commented Sep 23, 2013

@sqlumee As a side-effect, my solution disable the "automaticallyAdjustsScrollViewInsets" behavior. You may need to set contentInset manully after your view loaded.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Manully set contentInset.
    UIEdgeInset currentInset = self.tableView.contentInset;
    currentInset.top = self.navigationController.navigationBar.bounds.size.height;
    if (SYSTEM_VERSION_HIGHER_OR_EQUAL_THAN(@"7.0")) {
        self.automaticallyAdjustsScrollViewInsets = NO;
        // On iOS7, you need plus the height of status bar.
        currentInset.top += STATUS_BAR_HEIGHT;
    }
    self.tableView.contentInset = currentInset;

    // Some other code...
}

Additonally, try it on the lastest commit.

@sqlumee
Copy link

sqlumee commented Sep 23, 2013

is it going to be fixed in SVPullToRefresh? or something we have to do in each VC since now?

@sagiwei
Copy link

sagiwei commented Sep 24, 2013

@fanyj , nice solution, but I found set contentInset.top may cause animation lost when use triggerPullToRefresh to trigger refresh manually. The problem may caused by code in UIScrollView+SVPullToRefresh.m:

- (void)startAnimating{
    // if(fequalzero(self.scrollView.contentOffset.y) {
    if(fequalzero(self.scrollView.contentOffset.y + self.originalTopInset)){
        // [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, -self.frame.size.height) animated:YES];
        [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, -(self.frame.size.height+self.originalTopInset)) animated:YES];
        self.wasTriggeredByUser = NO;
    }
    else
        self.wasTriggeredByUser = YES;

    self.state = SVPullToRefreshStateLoading;
}

Don't forget self.originlTopInset, now it work fine for me in iOS7 and iOS6.

@limboy
Copy link

limboy commented Oct 12, 2013

scrollView's contentInset is set after viewDidLoad when automaticallyAdjustsScrollViewInsets is set YES, so when addPullToRefreshWithActionHandler in viewDidLoad, SVPullToRefresh's originalTopInset is still 0, a dirty fix is use dispatch_after.

double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        // 设置下拉刷新
        [self.tableView addPullToRefreshWithActionHandler:^{
        }];
    }];
});

@zwzmzd
Copy link

zwzmzd commented Oct 24, 2013

@sagiwei A good sloution, It works for my project.

@zquintana
Copy link

Is this going to be fixed in the main repo?

@mactive
Copy link

mactive commented Jan 16, 2014

@fanyj is worked in iOS 7. THX

@TouchG
Copy link

TouchG commented Jan 17, 2014

Here is what I do:

  • (void)viewDidLoad
    {
    [super viewDidLoad];

    // Manully set contentInset.
    UIEdgeInset currentInset = self.tableView.contentInset;
    currentInset.top = self.navigationController.navigationBar.bounds.size.height;
    if (SYSTEM_VERSION_HIGHER_OR_EQUAL_THAN(@"7.0")) {

         self.edgesForExtendedLayout = UIRectEdgeNone;
    

    }

    // Some other code…
    }

Basically,It's same with @fanyj ,but you don't care about the contentInsets.Also you can deselect "Under The Top Bar" in Attributes Inspector from you storyboard or nib file.
Uploading 屏幕快照 2014-01-17 下午2.29.44.png . . .

@ieliwb
Copy link

ieliwb commented Jun 27, 2014

I used @sagiwei fixed.
thanks.

@anhuijhy
Copy link

if we set automaticallyAdjustsScrollViewInsets we can modify the code as below
view.originalTopInset = self.contentInset.top + NavBarHeight + StatusBarHeight;
is this a way?

@anhuijhy
Copy link

if we set automaticallyAdjustsScrollViewInsets = YES we can modify the code as below
view.originalTopInset = self.contentInset.top + NavBarHeight + StatusBarHeight;
is this a way?

@Vishal2Deshai
Copy link

@fanyj thanks for Solving My Problem.

Only one line Solved My Issue (dance).

@gclsoft
Copy link

gclsoft commented Dec 21, 2014

I've solved by the way @fanyj said. But when I call [self.tableView.pullToRefreshView startAnimating];, the SVPullToRefresh doesn't display, only when I pull down the tableview by hand, it can display. How to solve it?

- (void)viewDidLoad {
    [super viewDidLoad];

    // Manully set contentInset.
    UIEdgeInsets currentInset = self.tableView.contentInset;
    currentInset.top = self.navigationController.navigationBar.bounds.size.height;
    //if (SYSTEM_VERSION_HIGHER_OR_EQUAL_THAN(@"7.0")) {
    self.automaticallyAdjustsScrollViewInsets = NO;
    // On iOS7, you need plus the height of status bar.
    CGRect rcStatus=[[UIApplication sharedApplication] statusBarFrame];
    currentInset.top += rcStatus.size.height;
    // }
    self.tableView.contentInset = currentInset;
    //self.edgesForExtendedLayout = UIRectEdgeNone;

@sagiwei
Copy link

sagiwei commented Dec 21, 2014

@gclsoft see my comment above, same problem.

@cmcnab
Copy link

cmcnab commented Sep 7, 2015

+1 for sagiwei's comment from Sep 24, 2013. Manually triggering pull to refresh wasn't working for me until I modified those lines.

@VincentSit
Copy link

@sagiwei Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests