[置顶] iOS初级开发之封装头部视图带图片旋转<继承UITableViewHeaderFooterView>
2016-11-07 18:12
519 查看
前言
我又来了,今天给大家带来的是,请大家看标题.对了,就是要做一个以TableView的分区为头部的一个展开视图控制器.可能就会有人问了,这么简单的控件,为甚还有写一篇博客呢?这也是实属没办法的事情,人在江湖身不由己嘛,好了现在也不多说了直接上代码,上面都有注释的很简单的(大神看到的话,可以指导一下小弟)一、关键代码
需要注意点:展开时需要标记位进行判断@interface DWEHeaderFooterView : UITableViewHeaderFooterView /**标记是否打开*/ @property (nonatomic, assign , getter=isOpenUp) BOOL openUp; /**标题*/ @property (nonatomic, strong) UILabel *titleLabel; /**分区*/ @property (nonatomic,assign) NSInteger section; /**点击block*/ @property (nonatomic, copy) void(^didTouchHeaderViewBlock)(DWEHeaderFooterView *aHeaderView); @end @interface DWEHeaderFooterView() /**旋转图片*/ @property (nonatomic, strong) UIImageView *imageView; /**标题背景*/ @property (nonatomic, strong) UIView *titleBgView; @end @implementation DWEHeaderFooterView @synthesize openUp = _openUp; - (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithReuseIdentifier:reuseIdentifier]; if (self) { //背景view UIView *bgView = [[UIView alloc]initWithFrame:CGRectZero]; bgView.backgroundColor = [UIColor whiteColor]; _titleBgView = bgView; [self.contentView addSubview:bgView]; //表头 _titleLabel = [[UILabel alloc]init]; _titleLabel.font = [UIFont systemFontOfSize:15]; _titleLabel.textColor = [UIColor blackColor]; [_titleLabel sizeToFit]; [self.contentView addSubview:_titleLabel]; //旋转图片 UIImage *image = [UIImage imageNamed:@"icon_Folding"]; _imageView = [[UIImageView alloc]initWithImage:image]; [self.contentView addSubview:_imageView]; } return self; } #pragma mark - SET GET - (BOOL)isOpenUp { return _openUp; } - (void)setOpenUp: 9463 (BOOL)openUp { _openUp = openUp; if (_openUp) { self.imageView.transform = CGAffineTransformMakeRotation(-M_PI); } else { self.imageView.transform = CGAffineTransformIdentity; } } #pragma mark - Event - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { __weak __typeof(self) ws = self; __strong __typeof(ws) ss = ws; if (_openUp) { [UIView animateWithDuration:0.2 animations:^{ ss.imageView.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { _openUp = !_openUp; if (_didTouchHeaderViewBlock) _didTouchHeaderViewBlock(ws); }]; } else { [UIView animateWithDuration:0.2 animations:^{ ss.imageView.transform = CGAffineTransformMakeRotation(-M_PI); } completion:^(BOOL finished) { _openUp = !_openUp; if (_didTouchHeaderViewBlock) _didTouchHeaderViewBlock(ws); }]; } } #pragma mark - layoutSubviews - (void)layoutSubviews { [super layoutSubviews]; CGFloat width = self.bounds.size.width; CGFloat height = self.bounds.size.height; _imageView.frame = CGRectMake(width - 42, height*0.5 - 11, 22, 22); _titleBgView.frame = CGRectMake(0, 1, width, height -2); _titleLabel.frame = CGRectMake(25, height*0.5 - 10, width- 140, 20); } @end
二、项目链接:
休闲咖-2千万人的技能分享平台,人人都可以参与,适合每一种职业.分享是一种生活,也是一种收获. 分享技能,传递价值,改变世界,从我开始。我们期待你的加入。
安卓app下载链接:
http://sj.qq.com/myapp/detail.htm?apkName=com.alligator.xiuxianba
苹果app下载链接:
https://itunes.apple.com/cn/app/xiu-xian-ka/id1160649870?mt=8
相关文章推荐
- &lt;转&gt;iOS开发拓展篇—封装音频…
- iOS开发 两个视图之间值传递的常用方法<三>
- iOS开发 两个视图之间值传递的常用方法<一>
- ios UItableView,UITableViewHeaderFooterView分组头部的重用机制,简单地仿射变换CGAffineTransform
- iOS开发 两个视图之间值传递的常用方法<五>
- Objective-C ,ios,iphone开发基础:多个视图(view)之间的切换,以及视图之间传值。使用parent <->dismiss
- iOS开发之UITableView点击头部控件图片旋转问题
- iOS开发 两个视图之间值传递的常用方法<四>
- iOS开发 两个视图之间值传递的常用方法<二>
- iOS开发>>>UIScrollView滚动条视图的使用
- iOS开发动画(Animation)图片360度不停旋转
- iOS开发>>>UITableView
- IOS开发笔记:编译时出现的错误<1>
- Android学习之 有关图片缓存问提的代码封装<二>
- 黑马程序员 JAVA基础<二> 面向对象之封装 继承 多态
- iOS开发之获取手机通讯录联系人信息<二>
- Android学习之 有关图片缓存问提的代码封装<一>
- 转载 iOS开发动画(Animation)图片360度不停旋转
- IOS视图切换动画效果<代码演示>
- 黑马程序员 Java初级<一>---> JAVA开发前奏