头部拉伸效果(iOS)

- (void)creatUI{

    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 170, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-20) style:UITableViewStylePlain];

    [self.view addSubview:myTableView];

    myTableView.backgroundColor = [UIColor redColor];

    

    myView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, [[UIScreen mainScreen] bounds].size.width, 150)];

    myView.backgroundColor = [UIColor blackColor];

    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];

    img.center = myView.center;

    img.image = [UIImage imageNamed:@"sjdlogo_Bnt@2x"];

    img.layer.masksToBounds = YES;

    img.layer.cornerRadius = 75/2;

    [myView addSubview:img];

    

    [self.view addSubview:myView];

    

    myTableView.delegate = self;

    myTableView.dataSource = self;

    [myTableView registerClass:NSClassFromString(@"UITableViewCell") forCellReuseIdentifier:@"cell"];

}

 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 20;

}

 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 50;

}

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row];

    return cell;

}

 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    

    if (scrollView.contentOffset.y <=  0) {

        yOffset  = scrollView.contentOffset.y;

        NSLog(@"%f", yOffset);

        

        CGRect frame = myView.frame;

        frame.size.height = 150-yOffset;

        

        myView.frame = frame;

        

        for (UIView *view in myView.subviews) {

            if ([view isKindOfClass:[UIImageView class]]) {

                view.frame = CGRectMake(0, 0, myView.frame.size.height/2, myView.frame.size.height/2);

                view.center = myView.center;

                view.layer.masksToBounds = YES;

                view.layer.cornerRadius = myView.frame.size.height/4;

            }

        }

    } else {

        return;

    }

 

}

 

posted @ 2015-10-10 17:34  一只小香猪  阅读(175)  评论(0)    收藏  举报