iOS开发——封装自己的下拉菜单
来源:互联网 发布:80端口关闭有什么影响 编辑:程序博客网 时间:2024/06/03 14:35
效果图
思路
1、图片的拉伸:
UIImage *image = [UIImage imageNamed:@"popover_background"]; image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(24, 0, 24, 0) resizingMode:UIImageResizingModeStretch];
-resizableImageWithCapInsets:resizingMode
方法的第二个参数,调整模式分为两种,平铺与拉伸。这里采用拉伸,可以保证背景的带箭头的框框按照内容大小正确地将其包围。
2、圆形过渡动画
具体实现方式可以参考这篇博客: iOS开发——圆形过渡动画。这里把代码摆上
CGRect originalRect = CGRectMake(point.x, point.y, 1, 1); self.startPath = [UIBezierPath bezierPathWithOvalInRect:originalRect]; CGPoint extremePoint = CGPointMake(point.x, point.y + contentView.frame.size.height); CGFloat radius = sqrtf(extremePoint.x * extremePoint.x + extremePoint.y * extremePoint.y); UIBezierPath *endPath = [UIBezierPath bezierPathWithOvalInRect: CGRectInset(originalRect, -radius, -radius)]; self.shapeLayer = [CAShapeLayer layer]; self.shapeLayer.path = endPath.CGPath; self.layer.mask = self.shapeLayer; if (animated) { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"]; animation.fromValue = (__bridge id)(self.startPath.CGPath); animation.toValue = (__bridge id)(endPath.CGPath); animation.duration = 0.3f; [self.shapeLayer addAnimation:animation forKey:@"begin"]; }
3、其他
①view的层级关系:
主要有两个控件,contentView为用户传入的view,一般是一个表给,用户需要自己规定这个contentView的宽高。
另一个是imageView充当背景图片,同时该imageView会作为用户传入的contentView的容器,
整个控件为一个View,背景透明,做mask用,当菜单处于打开状态时用户点击背景会使菜单收回。
当用户传入contentView后,重设其原点,同时更新imageView的大小使其将整个contentView包围。
最后,将这个整体加到window中,保证菜单处于最上层。
②坐标系转换
由用户传入一个控件来决定该菜单显示在哪时,需要用到坐标系转换。关于坐标系转换,之前的博客中也有记录,在此留一个简单的结论:
[viewA convertRect:viewA.bounds toView:viewB]—得到viewA在viewB坐标系下的bounds。
③CAAnimationDelegate中区分多个animation对象
首先在添加animation时为其设置标志key: [self.shapeLayer addAnimation:animation forKey:@"end"];
在代理方法中根据layer的方法拿:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { if (anim == [self.shapeLayer animationForKey:@"end"]) { self.shapeLayer.path = self.startPath.CGPath; [self removeFromSuperview]; }}
代码
源代码
0 0
- iOS开发——封装自己的下拉菜单
- ios开发-新浪微博10-(下拉菜单的二次封装 完整版)
- iOS 怎么封装一个三级下拉菜单?
- iOS开发 - 封装一个自己的按钮
- ios开发-新浪微博-09(下拉菜单封装一)
- 封装遮盖&下拉菜单
- 下拉选择菜单封装
- 下拉选择菜单封装
- iOS——分享自己封装的指示器CFHUD
- ios封装自己的表格上/下拉刷新框架,MJRefresh框架解析
- jQuery——下拉菜单的使用
- 下拉菜单—常见的省市
- ios之protocol和delegate——下拉菜单实例
- ios之protocol和delegate——下拉菜单实例
- ReactNative学习笔记--下拉选择菜单的简单封装
- ReactNative学习笔记--下拉选择菜单的简单封装
- ios开发-新浪微博08-下拉菜单的基本实现
- iOS实现下拉菜单
- 二分图的最大带权匹配
- 数据结构与算法——线性表链式存储结构(静态链表)
- 黑马程序员--异常体系
- 二分图最大匹配,点的最小覆盖,最小路径覆盖
- 支付宝手机网页即时到账接口(1)之相关信息介绍
- iOS开发——封装自己的下拉菜单
- 矩阵相乘
- javascript定义变量和优先级的问题
- 递归实现厄密多项式
- 我的iOS开发 3-Objective-C分支结构
- 【Java】Java的多态性
- 高斯消元
- [置顶] 亲,这就是遗传算法
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?