1

Inserted a CALayer, and then [CATransaction commit] in scrollViewDidScroll:

why it not reacts instantly in scrollViewDidScroll:?

to quick drag issues, there is a a flash blank.

q

slow handling is OK

img normal

Here is the code:

- (void)viewDidLoad {
    self.backLayer = [[CALayer alloc] init];
    self.backLayer.frame = CGRectMake(0, 0, KScreenWidth, 0);
    [self.view.layer addSublayer: self.backLayer];
    self.backLayer.backgroundColor = navigationBarBuleColor.CGColor;
    self.backLayer.actions = @{@"position":[NSNull null]};
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat y = scrollView.contentOffset.y;
    if (y>0) {
        self.backLayer.opacity = 0;
    }
    else{

        [CATransaction begin];
        [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
        CGRect frame = self.backLayer.frame;
        frame.size.height = (fabs(y));
        self.backLayer.frame = frame;
        self.backLayer.opacity = 1;
        [CATransaction commit];
    }
}

I have checked Update CALayer sublayers immediately.

And I use UIView, it is OK.

Here is the code:

- (void)viewDidLoad {
    self.assistView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0)];
    self.assistView.backgroundColor = navigationBarBuleColor;
    [self.view addSubview:self.assistView];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat y = scrollView.contentOffset.y;
    if (y>0) {
        self.assistView.alpha = 0;
    } else{
        CGRect frame = self.assistView.frame;
        frame.size.height = (fabs(y));
        self.assistView.frame = frame;
        self.assistView.alpha = 1;
        [self.view setNeedsLayout];
    }
}

what it the method of CALayer , equal to setNeedsLayout?

More info: I try to solve the problem with layer How to set UITableView empty space's backgroundColor different?

Cœur
  • 37,241
  • 25
  • 195
  • 267
black_pearl
  • 2,549
  • 1
  • 23
  • 36

0 Answers0