vlasov / CCBottomRefreshControl

MIT License
319 stars 77 forks source link

BottomRefreshControl layer zPosition results in appearance of refresh indicator on top of tableview #3

Open peterjkirby opened 10 years ago

peterjkirby commented 10 years ago

I have setup a bottomRefreshControl using the following code:

UIRefreshControl *refreshControl = [UIRefreshControl new];
 [refreshControl addTarget:self action:@selector(refresh)          
forControlEvents:UIControlEventValueChanged];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
 self.tableView.bottomRefreshControl = bottomRefreshControl;

When a user drags the tableView in the upwards direction, the bottomRefreshControl fades into place on top of the tableView rows that are being dragged upwards. This behavior differs from how the normal UIRefreshControl works; a UIRefreshControl on the top of a UITableView usually appears from beneath the tableView as a user drags the tableView downwards.

I was able to achieve this desired behavior by making a change to the following code to UIScrollView+BottomRefreshControl.m:

...
- (void)setBottomRefreshControl:(UIRefreshControl *)refreshControl {

    if (!self.context) {

        self.context = [CategoryContext new];

        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        tableView.userInteractionEnabled = NO;
        tableView.backgroundColor = [UIColor clearColor];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.transform = CGAffineTransformMakeRotation(M_PI);
        [tableView addSubview:refreshControl];
        tableView.layer.zPosition = -100; // CHANGE ADDED HERE...
        self.context.fakeTableView = tableView;

By adding a negative zPosition to the fakeTableView layer, the bottomRefreshControl appears from beneath the tableView as a user drags upwards.

The value of the zPosition can be any negative number, since the default value for layer zPosition's is 0.

yariksmirnov commented 10 years ago

I've tried this method, but refresh control is totally dissappeared. I use it not on root but pushed view controller, maybe problem in this? Could you give a piece of advice?

gdroel commented 8 years ago

I'm experiencing the same issue.