您的位置:首页 > 产品设计 > UI/UE

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];

//上面的对应的方法如下代码

#import <UIKit/UIKit.h>
#import "DelegateView.h"

@interface DelegateViewController : UIViewController

@end


View Code DelegateViewController.h
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: