⼀、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];错误写法