仿苹果Assistive Touch
来源:互联网 发布:windows 10控制面板 编辑:程序博客网 时间:2024/05/01 08:42
简单的实现苹果Assistive Touch。
自定义按钮:
//// YFAssistiveButton.m// 仿 Assistive Touch//// Created by dev on 16/6/21.// Copyright © 2016年 SWALLE. All rights reserved.//#import "YFAssistiveButton.h"@interface YFAssistiveButton(){ CGPoint _beginPoint;}@end@implementation YFAssistiveButton-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ [super touchesBegan:touches withEvent:event]; UITouch *touch = [touches anyObject]; _beginPoint = [touch locationInView:self];}-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touvh = [touches anyObject]; CGPoint currentPoint = [touvh locationInView:self]; CGFloat X = currentPoint.x - _beginPoint.x; CGFloat Y = currentPoint.y - _beginPoint.y; self.center = CGPointMake(self.center.x + X, self.center.y + Y);}-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ CGFloat W = self.frame.size.width/2 ; CGFloat H = self.frame.size.height/2; CGFloat KScreenW = [UIScreen mainScreen].bounds.size.width; CGFloat KScreenH = [UIScreen mainScreen].bounds.size.height; CGFloat margenTop = self.center.y; CGFloat margenBottom = KScreenH - self.center.y; [UIView animateWithDuration:.2 animations:^{ if (margenTop < 160) { self.center = CGPointMake(self.center.x + W, H); return; }else if (margenBottom < 160){ self.center = CGPointMake(self.center.x + W, KScreenH - H); return; }else{ if (self.center.x < KScreenW/2) { self.center = CGPointMake(W, self.center.y); return; }else if (self.center.x > KScreenW/2){ self.center = CGPointMake(KScreenW - W, self.center.y); return; } } }]; }@end
在控制器里面初始化自定义按钮
self.view.backgroundColor = [UIColor grayColor]; YFAssistiveButton *btn = [YFAssistiveButton buttonWithType:UIButtonTypeSystem]; _btn = btn; btn.layer.cornerRadius = 5; btn.frame = CGRectMake(5, 100, 50, 50); [btn setBackgroundImage:[UIImage imageNamed:@"Assistive Touch"] forState:UIControlStateNormal]; [self.view addSubview:btn];
0 0
- 仿苹果Assistive Touch
- 开发UI控件时遇到的问题(类似于苹果Assistive Touch)
- 仿苹果的EasyTouch
- 仿苹果进度条(progressDialog)
- 仿苹果弹性布局
- 仿苹果按钮
- Android:仿苹果按钮
- 苹果 iPod touch 卸载应用
- 仿苹果系统桌面任务栏
- Flex 仿苹果的动画
- Android 仿苹果滑动效果
- 仿苹果launcher 修改总结
- 仿苹果锁屏实现
- android仿苹果分段按钮
- android仿苹果弹性布局
- 高仿苹果通讯录布局
- 仿苹果的滑动开关
- 仿苹果Mac Dock任务栏
- Java学习资源推荐
- Android通知栏微技巧,那些你所没关注过的小细节
- 第一章 HTML标记与文档结构(HTML文档剖析)
- linux user mysql 破解
- android中颜色渐变动画
- 仿苹果Assistive Touch
- 第十一周项目日期时间类
- Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
- 连接共享文件夹时报错:发生系统错误 1219:不允许一个用户使用一个以上用户名与服务器或共享资源的多重连接
- AJAX编程实践
- 数据结构 C语言实现 双向链表的增加与删除节点
- fragment 嵌套
- makefile的语法及写法
- 无法访问linux上已经部署好的项目