tableView:实现导航栏渐变和顶部禁止弹簧效果

来源:互联网 发布:小猫淘宝客 编辑:程序博客网 时间:2024/04/29 09:51
- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, self.view.bounds.size.width, self.view.bounds.size.height+20)];    tableView.dataSource = self;    tableView.delegate = self;    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];        [self.view addSubview:tableView];        RACSignal *signal = [tableView rac_valuesForKeyPath:@"contentOffset" observer:self];    RAC(self.navigationController.navigationBar,alpha) = [signal map:^id(NSValue * x) {        CGFloat offset = tableView.contentOffset.y;        if (offset<=-20) {            tableView.bounces = NO;        }        else{            tableView.bounces = YES;        }        CGFloat delta = offset / 20.f + 1.f;        delta = MAX(0, delta);        CGFloat ofy = 200-CGRectGetMaxY(self.navigationController.navigationBar.frame);        CGFloat alp = (offset+20)/ofy;        return [NSNumber numberWithFloat:MIN(1, alp)];    }];    }- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    return 200;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 20;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];    cell.textLabel.text = @"hahahahahahahh";    return cell;}

 


0 0
原创粉丝点击