您的位置:首页 > 移动开发 > Swift

iOS-仿淘宝navigationBar双波纹(OC版本和Swift版本)

2017-01-07 15:44 405 查看

前言

上个月淘宝更新的APP的navigationBar上面有两个大波浪,看着很好玩,很多APP开始模仿,包括我们公司的APP也是,然后我就写了一个播放的View,方便各种环境下使用;

1.navigationBar

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor whiteColor];
[self.navigationController.navigationBar addSubview:self.headerView];
[self.navigationController.navigationBar sendSubviewToBack:self.headerView];
}

- (ZFJWaveView *)headerView{
if (!_headerView) {
_headerView = [[ZFJWaveView alloc] initWithFrame:CGRectMake(0, -20, self.view.frame.size.width, 64)];
_headerView.backgroundColor = [UIColor colorWithRed:1.000 green:0.318 blue:0.129 alpha:1.00];
_headerView.waveBlock = ^(CGFloat currentY){
};
[_headerView startWaveAnimation];
}
return _headerView;
}


Swift调用代码

self.view.backgroundColor = UIColor.white

headerView = ZFJWaveView(frame: CGRect(x: CGFloat(0), y: CGFloat(-20), width: CGFloat(self.view.frame.size.width), height: CGFloat(64)))
headerView.backgroundColor = UIColor(red: CGFloat(1.000), green: CGFloat(0.318), blue: CGFloat(0.129), alpha: CGFloat(1.00))
headerView.waveBlock = {(_ currentY: CGFloat) -> Void in
//print(currentY)
}
headerView.startWaveAnimation()

self.navigationController!.navigationBar.addSubview(headerView)
self.navigationController!.navigationBar.sendSubview(toBack: headerView)

效果如下:



2.其他(UITableview头部)

- (UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.backgroundColor = KBackgroundColor;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.separatorColor = [UIColor clearColor];
_tableView.tableHeaderView = self.headerView;
}
return _tableView;
}

- (ZFJWaveView *)headerView{
if (!_headerView) {
_headerView = [[ZFJWaveView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 265)];
__weak typeof(self)weakSelf = self;
_headerView.titleName = @"小荧星培训机构";
_headerView.detailName = @"机构ID:134611";
_headerView.btnTittleArr = @[@"主页",@"比赛"];
_headerView.selectType = ^(NSInteger selectIndex,NSString *selectIndexTitle){
weakSelf.selectType = selectIndex;
};
[_headerView startWaveAnimation];
[_headerView addSubview:weakSelf.headViewBackBtn];
}
return _headerView;
}
效果如下:



3.DEMO下载

OC版本点击下载

OC版本:http://download.csdn.net/detail/u014220518/9731412

Swift版本点击下载

Swift版本:http://download.csdn.net/detail/u014220518/9732721
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: