抖音app之所以“横扫”整个短视频领域,最主要的还是占据了短视频玩法的“先机”,其中在录制视频时添加背景音乐,是很多用户都非常喜欢的步骤,但是在抖音app开发时,添加背景音乐的功能也是需要技术实现的。今天就来分享下关于这一功能的大概实现流程。
1.在录制界面点击音乐,绘制UI
添加搜索框
-(UIView *)searchBg {
if (!_searchBg) {
_searchBg = [[UIView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight,_window_width,44)];
_searchBg.backgroundColor = [UIColor whiteColor];
_search = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0, _window_width,44)];
_search.backgroundImage = [PublicObj getImgWithColor:[UIColor whiteColor]];
_search.placeholder = @"搜索歌曲名称";
_search.delegate = self;
UITextField *textField ;
if (@available(iOS 13.0,*)) {
textField = _search.searchTextField;
}else {
textField = [_search valueForKey:@"_searchField"];
}
[textField setBackgroundColor:RGB_COLOR(@"#f9fafb", 1)];
// [textField setValue:GrayText forKeyPath:@"_placeholderLabel.textColor"];
// [textField setValue:[UIFont systemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
UIButton *clearBtn = [textField valueForKey:@"_clearButton"];
[clearBtn addTarget:self action:@selector(clickClearBtn) forControlEvents:UIControlEventTouchUpInside];
textField.textColor = GrayText;
textField.layer.cornerRadius = 18;
textField.layer.masksToBounds = YES;
[_searchBg addSubview:_search];
}
return _searchBg;
}
2.添加音乐分类界面
- (MusicH