[self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{ CGPoint oldPoint = [change[@"old"] CGPointValue]; CGPoint newPoint = [change[@"new"] CGPointValue]; // NSLog(@"%@",change); CGFloat newY = newPoint.y; CGFloat oldY = oldPoint.y; if ( newY - oldY > 0) { //判断 self.imageView.y -= newY; self.tableView.y = self.imageView.bottom; [self.tableView setContentOffset:CGPointMake(0, 0)]; } else if ( newY - oldY < 0) { // self.imageView.y = self.imageView.y - newY; // if (self.imageView.y >= 0) { // self.imageView.y = 0; // } // self.tableView.y = self.imageView.bottom; self.imageView.y -= newY; self.tableView.y = self.imageView.bottom; [self.tableView setContentOffset:CGPointMake(0, 0)]; } }
https://github.com/yongliangP/YLSpringHeader
https://github.com/Cloudox/ScrollShowHeaderDemo
https://www.jianshu.com/p/8e4ed860d460
section 圆角 阴影
https://www.cnblogs.com/yeng/p/10540167.html
//===============Cell================== @interface SubCell : UITableViewCell @property (nonatomic, strong) SubCellShadowView *bgView; @property (nonatomic, strong) NSIndexPath *indexPath; @property (nonatomic) NSInteger rowInSection;//每一组的行数 @end @implementation SubCell - (void)awakeFromNib { [super awakeFromNib]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.clipsToBounds = NO; SubCellShadowView *bgView = [[SubCellShadowView alloc] init]; [self insertSubview:bgView atIndex:0]; self.bgView= bgView; CAShapeLayer *shadow = [CAShapeLayer layer]; shadow.shadowColor = [UIColor blackColor].CGColor; shadow.shadowOffset=CGSizeMake(0,0); shadow.shadowOpacity=0.15; [bgView.layeraddSublayer:shadow]; bgView.shadowLayer= shadow; CALayer*line = [CALayerlayer]; line.backgroundColor = [UIColor groupTableViewBackgroundColor].CGColor; [bgView.layeraddSublayer:line]; bgView.separatorLine= line; } -(void)layoutSubviews{ [super layoutSubviews]; UIBezierPath*bgBezierPath =nil; CGFloat cornerRaduis =7.0;//觉得阴影大的可以把半径调小,半径大的话阴影面积会变大 if(self.indexPath.row==0 && self.rowInSection==1) {//单组单行 self.bgView.clipsToBounds=NO; self.bgView.frame=self.bounds; CGRect rect = UIEdgeInsetsInsetRect(self.bgView.bounds, UIEdgeInsetsMake(0, 15, 0, 15)); bgBezierPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(cornerRaduis, cornerRaduis)]; }elseif(self.indexPath.row==0) {// 第一行 self.bgView.clipsToBounds=YES; self.bgView.frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(-5, 0, 0, 0)); CGRect rect = UIEdgeInsetsInsetRect(self.bgView.bounds, UIEdgeInsetsMake(5, 15, 0, 15)); bgBezierPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(cornerRaduis, cornerRaduis)]; }elseif(self.indexPath.row==self.rowInSection-1) {// 最后一行 self.bgView.clipsToBounds=YES; self.bgView.frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 0, -5, 0)); CGRect rect = UIEdgeInsetsInsetRect(self.bgView.bounds, UIEdgeInsetsMake(0, 15, 5, 15)); bgBezierPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(cornerRaduis, cornerRaduis)]; }else{// 中间行 self.bgView.clipsToBounds=YES; self.bgView.frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 0, 0, 0)); CGRect rect = UIEdgeInsetsInsetRect(self.bgView.bounds, UIEdgeInsetsMake(0, 15, 0, 15)); bgBezierPath = [UIBezierPathbezierPathWithRect:rect]; } self.bgView.shadowLayer.path= bgBezierPath.CGPath; self.bgView.shadowLayer.shadowPath= bgBezierPath.CGPath; self.bgView.shadowLayer.fillColor = [UIColor whiteColor].CGColor; //分割线 非单组单行 非最后一行 if(!(self.indexPath.row==0&&self.rowInSection==1) && !(self.indexPath.row==self.rowInSection-1)) { self.bgView.separatorLine.frame = CGRectMake(self.bgView.frame.origin.x+30, self.bgView.frame.size.height-1, self.bgView.frame.size.width-30*2, 1.0); } } @end