跟随移动 View随着tableView的滑动移动KVO

 [_tableViewaddObserver:selfforKeyPath:@"contentOffset"options:NSKeyValueObservingOptionNewcontext:nil];

-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context

{

   if([keyPathisEqualToString:@"contentOffset"])

    {

       CGPointnewOffset = [change[@"new"]CGPointValue];

        [selfupdateSubViewsWithScrollOffset:newOffset];

    }

}

-(void)updateSubViewsWithScrollOffset:(CGPoint)newOffset{


   //吸顶效果float destinaOffset = -50;

   floatdestinaOffset =0;

   floatstartChangeOffset = -_tableView.contentInset.top;

    newOffset =CGPointMake(newOffset.x, newOffset.ydestinaOffset?destinaOffset:newOffset.y));

   floatnewY = -newOffset.y-_tableView.contentInset.top+kNavBarHeight;

   _headView.frame=CGRectMake(0, newY,_headView.frame.size.width,_headView.frame.size.height);


}

你可能感兴趣的:(跟随移动 View随着tableView的滑动移动KVO)