使用了CAShapeLayer
创建一对文件继承CAShapeLayer
//
// headLayer.h
// UseMMDrawer
//
// Created by fangliguo on 16/7/19.
// Copyright © 2016年 fangliguo. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
@interface headLayer : CAShapeLayer
@end
//
// headLayer.m
// UseMMDrawer
//
// Created by fangliguo on 16/7/19.
// Copyright © 2016年 fangliguo. All rights reserved.
//
#import "headLayer.h"
@interface headLayer()
@property (nonatomic, strong) UIBezierPath *circleSmallPath;
@end
@implementation headLayer
- (instancetype)init{
self = [super init];
if (self) {
self.fillColor = [UIColor orangeColor].CGColor;// 填充颜色
self.path = self.aaPath.CGPath;
}
return self;
}
- (UIBezierPath *)aaPath {
if (!_circleSmallPath) {
// 视图的大小是100
_circleSmallPath = [[UIBezierPath alloc] init];
[_circleSmallPath moveToPoint:CGPointMake(0, 0)];
[_circleSmallPath addLineToPoint:CGPointMake(0, 150)];
[_circleSmallPath addCurveToPoint:CGPointMake(375, 150) controlPoint1:CGPointMake(375/2, 200) controlPoint2:CGPointMake(375, 150)];
[_circleSmallPath addLineToPoint:CGPointMake(375, 150)];
[_circleSmallPath addLineToPoint:CGPointMake(375, 0)];
[_circleSmallPath closePath];
}
return _circleSmallPath;
}
@end
实现页面 .m文件
//
// TViewController.m
// UseMMDrawer
//
// Created by fangliguo on 16/7/19.
// Copyright © 2016年 fangliguo. All rights reserved.
//
#import "TViewController.h"
#import "headLayer.h"
@interface TViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UIView *backView;
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *titleArr;
@end
@implementation TViewController
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
self.titleArr = [NSMutableArray arrayWithObjects:@"首页",@"好友",@"美食",@"汽车",@"热门",@"风景",@"幻城",@"呵呵",@"哈哈", nil];
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
// self.navigationController.navigationBar.hidden = YES;
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 170)];
self.tableView.tableHeaderView = headView;
headLayer *layer = [[headLayer alloc] init];
[headView.layer addSublayer:layer];
UIImageView *head = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"屏幕快照 2016-07-08 下午4.57.11"]];
[headView addSubview:head];
head.layer.cornerRadius = 25;
head.layer.masksToBounds = YES;
head.frame = CGRectMake(375/2 - 25, 100, 50, 50);
// headView.backgroundColor = [UIColor lightGrayColor];
backView = [[UIView alloc] initWithFrame:CGRectMake(0, -0, self.view.bounds.size.width, 0)];
backView.backgroundColor = [UIColor orangeColor];
[self.tableView addSubview:backView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.titleArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *reuse = @"reuse";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
}
cell.textLabel.text = self.titleArr[indexPath.row];
return cell;
}
//只要滑动就会触发
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//获取偏移量
CGFloat y=scrollView.contentOffset.y;
//NSLog(@"%g",y);
if (y<0) {
backView.frame=CGRectMake(0, y, self.view.frame.size.width, -y);
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}