九宫格手势解锁
来源:互联网 发布:js radio 取消选中 编辑:程序博客网 时间:2024/04/27 19:37
由于没有图片素材实现效果比较简单》
重新添加一个继承与UIView 的类
YFNineFunctionView.h
初始化时加载按钮,并设置属性
- (instancetype)init{ self = [super init]; if (self) { //初始化时加载视图 [self setUpView]; } return self;}//加载九个视图按钮,并且设置按钮属性-(void)setUpView{ for (int i = 0; i < 9; i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.userInteractionEnabled = NO; [btn.layer setMasksToBounds:YES]; //设置圆形按钮 btn.layer.cornerRadius = 40; btn.userInteractionEnabled = NO; //设置边框 btn.layer.borderWidth = 2.0; //[btn.layer setBorderWidth:2.0]; //a设置边框颜色 CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGColorRef color = CGColorCreate(colorSpaceRef, (CGFloat[]){217/255.0,240/255.0,255/255.0,1}); btn.layer.borderColor = color; [self addSubview:btn]; }}
在layoutSubviews中布局按钮位置
-(void)layoutSubviews{ [super layoutSubviews]; float Width = 80; float Height = 80; float margon = 30; for (int i = 0; i < 9; i++) { UIButton *btn = (UIButton *)self.subviews[i]; btn.tag = i+1; btn.frame = CGRectMake((i/3)*(Width + margon), (i%3)*(Width + margon), Width, Height);}}
处理视图的一系列触摸事件
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)even{ CGPoint point = [self getCurrentPoint:touches]; UIButton *btn = [self getCurrentButton:point]; if (btn&&btn.selected != YES) { btn.selected = YES; [self.buttons addObject:btn]; } [self setNeedsDisplay];}-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ CGPoint point = [self getCurrentPoint:touches]; UIButton *btn = [self getCurrentButton:point]; if (btn&&btn.selected != YES) { btn.selected = YES; [self.buttons addObject:btn]; } [self setNeedsDisplay];}-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ }//获得点击点-(CGPoint)getCurrentPoint:(NSSet*)touches{ UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:touch.view]; return point;}//获得点击处的按钮-(UIButton *)getCurrentButton:(CGPoint)point{ for (UIButton *btn in self.subviews) { //判断point是否在按钮内 if (CGRectContainsPoint(btn.frame, point)) { return btn; } } return nil;}
绘制线条
//绘图-(void)drawRect:(CGRect)rect{ //获取上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); for (int i = 0; i < self.buttons.count; i++) { UIButton *btn=self.buttons[i]; if (0==i) { //设置起点(注意连接的是中点) // CGContextMoveToPoint(ctx, btn.frame.origin.x, btn.frame.origin.y); CGContextMoveToPoint(ctx, btn.center.x, btn.center.y); }else { // CGContextAddLineToPoint(ctx, btn.frame.origin.x, btn.frame.origin.y); CGContextAddLineToPoint(ctx, btn.center.x, btn.center.y); } } CGContextSetLineWidth(ctx, 10); CGContextSetRGBStrokeColor(ctx, 20/255.0, 107/255.0, 153/255.0, 1); CGContextStrokePath(ctx);}
FNineFunctionView
YFNineFunctionView
0 0
- 手势解锁-九宫格
- 九宫格手势解锁
- 九宫格手势解锁
- 自定义九宫格手势解锁
- Android九宫格手势解锁
- Android手势解锁, 九宫格解锁
- XMG Quartz2D 手势解锁(九宫格)
- iOS 九宫格连线手势解锁
- 自定义View----Android九宫格手势密码解锁
- 九点(九宫格)式手势解锁自定义view
- Unity制作九宫格手机手势解锁密码
- android 自定义view实现九宫格手势解锁
- 九点(九宫格)式手势解锁自定义view
- 自定义View----Android九宫格手势密码解锁
- (4.2.42)手势解锁之九宫格控件PatternLockView
- (4.2.43)手势解锁之九宫格控件GestureLockView
- iOS-高仿支付宝手势解锁(九宫格)
- 自定义view之九宫格手势解锁空间
- UIView事件传递
- 两个链表的第一个公共结点
- css3边框
- 【Python学习笔记】文档测试
- win7升级win10后,sql2005/2012打不开出错完美解决方案
- 九宫格手势解锁
- build.gradle
- kylin调试之路
- SQL Server DBA日常检查常用SQL
- [awk] 一行命令处理文本的解析输出格式OFS
- Oracle问题imp-10019:由于ORACLE错误12899而拒绝行
- swiper的基础使用(二十二)
- 多重滤镜
- 整数解