本文实例为大家分享了iOS tableVIEw实现头部拉伸改变,导航条渐变色的具体代码,供大家参考,具体内容如下
#import "tableVIEwController.h"static Nsstring *IDent = @"cell";#define RGBA(r,g,b,a) [UIcolor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f Alpha:a]#define RGB(r,b) RGBA(r,1.0f)#define ZhuTicolor RGB(76,16,198)#define ZhuTicolorAlpha(Alpha) RGBA(76,198,Alpha)// 判断是否是iPhone X#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125,2436),[[UIScreen mainScreen] currentMode].size) : NO)// 状态栏高度#define STATUS_bar_HEIGHT (iPhoneX ? 44.f : 20.f)// 导航栏高度#define NAVIGATION_bar_HEIGHT (iPhoneX ? 88.f : 64.f)// tabbar高度#define TAB_bar_HEIGHT (iPhoneX ? (49.f + 34.f) : 49.f)// home indicator#define HOME_INDICATOR_HEIGHT (iPhoneX ? 34.f : 0.f)#define ScreenWIDth ([UIScreen mainScreen].bounds.size.wIDth)#define ScreenHeight ([UIScreen mainScreen].bounds.size.height)#define imageHight 200@interface tableVIEwController ()@property (nonatomic,strong) UIImageVIEw *headImage;@property (nonatomic,strong) UIVIEw *headerBackVIEw;@property (nonatomic,strong) UIVIEw *mengVIEw;@end@implementation tableVIEwController- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; [self.tableVIEw registerClass:[UItableVIEwCell class] forCellReuseIDentifIEr:IDent]; self.vIEw.backgroundcolor = [UIcolor redcolor]; self.tableVIEw.tableheaderVIEw = self.headerBackVIEw; [self.headerBackVIEw addSubvIEw:self.headImage]; [self.headImage addSubvIEw:self.mengVIEw]; [self navCleanFromAlpha:0];}-(voID)navCleanFromAlpha:(CGfloat)Alpha{ [self.navigationController.navigationbar setBackgroundImage:[self createImageWithcolor:ZhuTicolorAlpha(Alpha)] forbarMetrics:UIbarMetricsDefault]; self.navigationController.navigationbar.shadowImage = [UIImage new];}-(UIImage*) createImageWithcolor:(UIcolor*) color{ CGRect rect=CGRectMake(0.0f,0.0f,1.0f,1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillcolorWithcolor(context,[color CGcolor]); CGContextFillRect(context,rect); UIImage *theImage = UIGraphicsGetimageFromCurrentimageContext(); UIGraphicsEndImageContext(); return theImage;}-(UIImageVIEw *)headImage{ if(!_headImage) { _headImage= [[UIImageVIEw alloc]initWithFrame: self.headerBackVIEw.bounds]; _headImage.image = [UIImage imagenamed:@"1024"]; } return _headImage;}-(UIVIEw *)mengVIEw{ if (!_mengVIEw) { _mengVIEw = [[UIVIEw alloc]initWithFrame:self.headerBackVIEw.bounds]; _mengVIEw.backgroundcolor = RGBA(1,1,0.1); } return _mengVIEw;}-(UIVIEw *)headerBackVIEw{ if (!_headerBackVIEw) { _headerBackVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,ScreenWIDth,imageHight)]; [_headerBackVIEw setBackgroundcolor:[UIcolor lightGraycolor]]; } return _headerBackVIEw;}- (voID)dIDReceiveMemoryWarning { [super dIDReceiveMemoryWarning]; // dispose of any resources that can be recreated.}- (voID)scrollVIEwDIDScroll:(UIScrollVIEw *)scrollVIEw{ //---------------------- 图片拉升 ------------------------- //图片高度 CGfloat imageHeight = self.headerBackVIEw.frame.size.height; //图片宽度 CGfloat imageWIDth = ScreenWIDth; //图片上下偏移量 CGfloat imageOffsetY = scrollVIEw.contentOffset.y;// NSLog(@"图片上下偏移量 imageOffsetY:%f ->",imageOffsetY); //上移 if (imageOffsetY < 0) { CGfloat totalOffset = imageHeight + ABS(imageOffsetY); CGfloat f = totalOffset / imageHeight; self.headImage.frame = CGRectMake(-(imageWIDth * f - imageWIDth) * 0.5,imageOffsetY,imageWIDth * f,totalOffset); self.mengVIEw.frame = self.headImage.bounds; } //------------------- 导航条颜色渐变 ---------------------------- CGfloat tableVIEwOffsetY = [self.tableVIEw rectForSection:0].origin.y - NAVIGATION_bar_HEIGHT; CGfloat contentOffsetY = scrollVIEw.contentOffset.y; if (contentOffsetY >= tableVIEwOffsetY) {// scrollVIEw.contentOffset = CGPointMake(0,tableVIEwOffsetY); //定位 [self navCleanFromAlpha:1]; } else { CGfloat Alpha = scrollVIEw.contentOffset.y/imageHight; if (Alpha >= 1) { Alpha = 1; } if (Alpha <= 0) { Alpha = 0; } NSLog(@"%.2f",Alpha); [self navCleanFromAlpha:Alpha]; }}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { return 20;}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:IDent forIndexPath:indexPath]; // Configure the cell... cell.textLabel.text = [Nsstring stringWithFormat:@"asdada = %zd",indexPath.row]; return cell;}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
您可能感兴趣的文章:iOS实现点击图片放大和长按保存图片的示例iOS 点击图片放大效果的实现解决iOS11图片下拉放大出现信号栏白条的BUG问题利用iOS手势与scrollVIEw代理实现图片的放大缩小iOS tableVIEw实现顶部图片拉伸效果iOS tablevIEw实现顶部拉伸效果iOS tableVIEw头视图根据偏移量下拉缩放效果iOS应用开发中UItableVIEw的分割线的一些设置技巧IOS UItableVIEw和UItableVIEwCell的几种样式详细介绍iOS tableVIEw实现下拉图片放大效果 总结以上是内存溢出为你收集整理的iOS tableView实现头部拉伸并改变导航条渐变色全部内容,希望文章能够帮你解决iOS tableView实现头部拉伸并改变导航条渐变色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)