iOS开发Navigation导航栏渐变

释放双眼,带上耳机,听听看~!

方法有多种,无外乎监听scrollView变化,通过代理方法实现。
下面是比较简单直观的方法:

-(void)viewWillAppear:(BOOL)animated{
[superviewWillAppear:animated];
if (self.navigationController) {
[self.navigationControllersetNavigationBarHidden:YES animated:animated];
}
}
-(void)viewDidDisappear:(BOOL)animated{
[superviewDidDisappear:animated];
if (self.navigationController) {
[self.navigationControllersetNavigationBarHidden:NOanimated:NO];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y < 0) {
[selfshowView:_naviViewhidden:YES];
[selfsetStatusBarStyle:UIStatusBarStyleDefault];
}else if(scrollView.contentOffset.y > 50) {
[selfshowView:_naviViewhidden:NO];
CGFloat alpha = MIN(1, 1 - ((50 + 64 - scrollView.contentOffset.y) / 64));
[_naviViewsetBackgroundColor:[[UIColorwhiteColor] colorWithAlphaComponent:alpha]];
}else{
[selfshowView:_naviViewhidden:NO];
[_naviViewsetBackgroundColor:[[UIColorwhiteColor] colorWithAlphaComponent:0.0f]];
}
}
-(void)showView:(UIView *)view hidden:(BOOL)hidden{
CATransition *animation = [CATransitionanimation];
animation.type = kCATransitionFade;
animation.duration = 0.4;
[view.layeraddAnimation:animation forKey:nil];
view.hidden = hidden;
}
//根据数组随机生成一个长度为3内容不重复的数组
-(NSArray*)createRandomArray:(NSMutableArray*)mutableArray{
if (mutableArray.count < 4) {
return mutableArray;
}else{
NSMutableArray *startArray = [NSMutableArray array];
NSMutableArray *resultArray=[[NSMutableArray alloc] initWithCapacity:0];
for (NSInteger i = 0; i < mutableArray.count; i++) {
[startArray addObject:[NSString stringWithFormat:@"%ld",i]];
}
for (int i = 0; i<3; i++) {
int t = arc4random()%startArray.count;
resultArray[i] = startArray[t];
startArray[t] = [startArray lastObject];
[startArray removeLastObject];
}
NSInteger i = [resultArray[0] integerValue];
NSInteger j = [resultArray[1] integerValue];
NSInteger k = [resultArray[2] integerValue];
return @[mutableArray[i], mutableArray[j], mutableArray[k]];
}
}

 

人已赞赏
iOS文章

ios 强制UICollectionView停止滚动

2020-5-15 15:45:08

iOS文章

iOS MD5使用

2020-5-15 16:47:04

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索