UI:target-action设计模式、手势识别器
2015-09-02 13:26
429 查看
⼀、target/action设计模式
⼆、代理设计模式
三、UIImageView
四、⼿势识别器
target/action设计模式
耦合是衡量⼀个程序写的好坏的标准之⼀,
耦合是衡量模块与模块之间关联程度的指标
“⾼内聚,低耦合”是⾯向对象编程的核⼼思想。高内聚:功能上强大,低耦合:就是与其他类的关联性程度低
(注意:在定义代理的属性的时候属性的属性要用 assign)
手势识别的基类:UIGestureRecognizer 提供了手势识别的基本功能,他有7个手势 (轻拍手势、长按手势、轻扫手势、平移手势、捏合手势、旋转、边缘旋转)
1.轻怕手势 UITapGestureRecognizer
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeViewBackgroundColor:)];
tapGesture.numberOfTapsRequired = 2;//点两次
tapGesture.numberOfTouchesRequired = 2;//需要两个手指
[aView addGestureRecognizer:tapGesture];
[tapGesture release];
2.长按手势 UILongPressGestureRecognizer
UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(changeViewBackgroundColor:)];
longPress.numberOfTapsRequired = 2;//拍两次
longPress.numberOfTouchesRequired = 2;//需要两个手指
[aView addGestureRecognizer:longPress];
//// [aView addSubview:longPress];错误写法🙅
[longPress release];
3.轻扫手势 UISwipeGestureRecognizer
UISwipeGestureRecognizer * swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipe:)];
//设置轻扫的方向
//轻扫
//一次最多只能识别两种手势,默认的方向是向右轻扫
//上下不能在一起 左右不能在一起
swipe.direction = UISwipeGestureRecognizerDirectionRight;//向右
UISwipeGestureRecognizer * leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleLeftSwip:)];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;//向左
UISwipeGestureRecognizer * uPSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleUpSwip:)];
uPSwipe.direction = UISwipeGestureRecognizerDirectionUp;
UISwipeGestureRecognizer * DownSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleDownSwip:)];
DownSwipe.direction = UISwipeGestureRecognizerDirectionDown;
[greenView addGestureRecognizer:leftSwipe];
[greenView addGestureRecognizer:uPSwipe];
[greenView addGestureRecognizer:DownSwipe];
[greenView addGestureRecognizer:swipe];
[swipe release];
[leftSwipe release];
[uPSwipe release];
[DownSwipe release];
4.平移手势 UIPanGestureRecognizer
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[greenView addGestureRecognizer:pan];
[pan release];
5.捏合手势 UIPinchGestureRecognizer
UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
[aView addGestureRecognizer:pinch];
[pinch release];
6.旋转 UIRotationGestureRecognizer
UIRotationGestureRecognizer * rotate = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(handleRotate:)];
[aView addGestureRecognizer:rotate];
[rotate release];
7.边缘旋转 UIScreenEdgePanGestureRecognizer
UIScreenEdgePanGestureRecognizer * screenPan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(handleScreenPan:)];
[aView addGestureRecognizer:screenPan];
screenPan.edges = UIRectEdgeLeft;//如果改为右边的话,本例不能实现,因为视图不在当前窗口的边缘 (不要改为 上 和 下 他们分别是:通知)
[screenPan release];
//上面的对应的方法如下代码
View Code DelegateViewController.h
⼆、代理设计模式
三、UIImageView
四、⼿势识别器
target/action设计模式
耦合是衡量⼀个程序写的好坏的标准之⼀,
耦合是衡量模块与模块之间关联程度的指标
“⾼内聚,低耦合”是⾯向对象编程的核⼼思想。高内聚:功能上强大,低耦合:就是与其他类的关联性程度低
(注意:在定义代理的属性的时候属性的属性要用 assign)
手势识别的基类:UIGestureRecognizer 提供了手势识别的基本功能,他有7个手势 (轻拍手势、长按手势、轻扫手势、平移手势、捏合手势、旋转、边缘旋转)
1.轻怕手势 UITapGestureRecognizer
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeViewBackgroundColor:)];
tapGesture.numberOfTapsRequired = 2;//点两次
tapGesture.numberOfTouchesRequired = 2;//需要两个手指
[aView addGestureRecognizer:tapGesture];
[tapGesture release];
2.长按手势 UILongPressGestureRecognizer
UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(changeViewBackgroundColor:)];
longPress.numberOfTapsRequired = 2;//拍两次
longPress.numberOfTouchesRequired = 2;//需要两个手指
[aView addGestureRecognizer:longPress];
//// [aView addSubview:longPress];错误写法🙅
[longPress release];
3.轻扫手势 UISwipeGestureRecognizer
UISwipeGestureRecognizer * swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipe:)];
//设置轻扫的方向
//轻扫
//一次最多只能识别两种手势,默认的方向是向右轻扫
//上下不能在一起 左右不能在一起
swipe.direction = UISwipeGestureRecognizerDirectionRight;//向右
UISwipeGestureRecognizer * leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleLeftSwip:)];
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;//向左
UISwipeGestureRecognizer * uPSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleUpSwip:)];
uPSwipe.direction = UISwipeGestureRecognizerDirectionUp;
UISwipeGestureRecognizer * DownSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleDownSwip:)];
DownSwipe.direction = UISwipeGestureRecognizerDirectionDown;
[greenView addGestureRecognizer:leftSwipe];
[greenView addGestureRecognizer:uPSwipe];
[greenView addGestureRecognizer:DownSwipe];
[greenView addGestureRecognizer:swipe];
[swipe release];
[leftSwipe release];
[uPSwipe release];
[DownSwipe release];
4.平移手势 UIPanGestureRecognizer
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[greenView addGestureRecognizer:pan];
[pan release];
5.捏合手势 UIPinchGestureRecognizer
UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
[aView addGestureRecognizer:pinch];
[pinch release];
6.旋转 UIRotationGestureRecognizer
UIRotationGestureRecognizer * rotate = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(handleRotate:)];
[aView addGestureRecognizer:rotate];
[rotate release];
7.边缘旋转 UIScreenEdgePanGestureRecognizer
UIScreenEdgePanGestureRecognizer * screenPan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(handleScreenPan:)];
[aView addGestureRecognizer:screenPan];
screenPan.edges = UIRectEdgeLeft;//如果改为右边的话,本例不能实现,因为视图不在当前窗口的边缘 (不要改为 上 和 下 他们分别是:通知)
[screenPan release];
//上面的对应的方法如下代码
#import <UIKit/UIKit.h> #import "DelegateView.h" @interface DelegateViewController : UIViewController @end
View Code DelegateViewController.h
相关文章推荐
- Algorithms—96.Unique Binary Search Trees
- 怎么入门iOS之OC_UI晋级学什么、
- [LeetCode]N-Queens II
- UML建模之时序图(Sequence Diagram)
- Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask等
- Android 教你打造炫酷的ViewPagerIndicator 不仅仅是高仿MIUI
- Java中字符串探索—-String ,StringBuffer ,StringBuilder及字符串缓存池
- 转 -- MVC+EF easyui dataGrid 动态加载分页表格
- OS开发UI篇—Quartz2D简单使用
- mosquitto_pub和mosquitto_sub 命令参数说明
- 遍历一个map,从中取得key 和value。不知道key的情况下取value。
- LeetCode "Closest Binary Search Tree Value II"
- PAT-01-复杂度2 Maximum Subsequence Sum
- 改变UISearchBar的文本颜色
- 关于aque.h头文件
- EasyUI中combogrid的使用方法
- UVA 120 Stacks of Flapjacks (STL deque&reverse)
- ngui 的scrollview grid 只有一个子对象时 不会弹回
- soapUI接口测试工具所有版本下载地址
- Kanzi UI Solution