IOS UIEvent小结
来源:互联网 发布:矩阵的模怎么求 编辑:程序博客网 时间:2024/04/29 02:19
在IOS开发中我们通常会用到手势 但UIEvent 也必不可少 相比手势 更加直接/* uievent 是由设备部或对硬件的操作 每个事件都是一个uievent 对象 ios的事件有三种 触摸事件 摇晃事件 远程控制事件 触摸事件是由用户 都屏幕触摸产生的事件 对于 UIView或者其子类可以接收到触摸事件 只是没有作出响应 如果想要作出相响应 就要实现以下方法 */-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //当手指触摸屏幕时(刚开始接触)// [self modifiySuperviewColor];// [self modifySelfviewColor]; //touches存储触摸屏幕的手指对象,每一个手指对象都是一个UITouch的对象 NSLog(@"%lu",[touches count]); //随机色 //单机改变自身颜色// 1,获取手指对象 UITouch *touch1 = [touches anyObject];// 2,获取手指点击次数 if ([touch1 tapCount] == 2) { //取消之前的任务 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(modifySelfviewColor) object:nil]; [self performSelector:@selector(modifiySuperviewColor) withObject:nil afterDelay:0.3]; }else if([touch1 tapCount] == 1){ [self performSelector:@selector(modifySelfviewColor) withObject:nil afterDelay:0.3]; }else if([touch1 tapCount] == 3){ [self modifySelfviewLocation]; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(modifiySuperviewColor) object:nil]; } NSLog(@"%s",__FUNCTION__);}-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ //当触摸被取消时 (前提是手指之前在触摸屏幕)// 例如当电话进入时 NSLog(@"%s",__FUNCTION__);}-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ //当手指离开屏幕时 (触摸结束)// [self modifySelfviewLocation]; NSLog(@"%s",__FUNCTION__);}-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ //当是一直触摸屏幕并且在视图内移动时 NSLog(@"%s",__FUNCTION__);}//修改自身颜色-(void)modifySelfviewColor{ self.backgroundColor = [UIColor randomColor];}//修改父视图颜色-(void)modifiySuperviewColor{ self.superview.backgroundColor = [UIColor randomColor];}//改变自身位置-(void)modifySelfviewLocation{ }#import "UIColor+RandomColor.h"@implementation UIColor (RandomColor)+(UIColor *)randomColor{ return [self colorWithRed:arc4random() % 256 /255.0 green:arc4random() % 256 /255.0 blue:arc4random() % 256 /255.0 alpha:1.0];}@end
0 0
- IOS UIEvent小结
- iOS-UIEvent
- IOS开发之UIEvent
- iOS UITouch、UIEvent
- iOS UIEvent 事件传递 流程
- ios触摸事件一 :UIEvent
- UIEvent
- UIEvent
- iOS SDK详解之UIEvent/UITouch
- iOS UIEvent事件及UIResponder响应者
- iOS编程-------事件处理UIEvent / 触摸事件UITouch
- IOS学习之——UIEvent 控件的学习
- 关注 UIEvent
- 9.UIEvent
- UIEvent简介
- UIevent事件
- UIEvent,UIResponder
- UIEvent - 1
- Linux进程管理(第二版) --进程管理命令
- Java窗体中按钮布局问题
- 模拟退火算法
- J2EE学习计划
- SDUT 2498-AOE网上的关键路径(spfa+字典序路径)
- IOS UIEvent小结
- Oracle 的ROWID 和 ROWNUM
- OCR 基本知识
- 小球下落(二叉树)!!!!
- BusyBox 编译出现问题---scripts/kconfig/lxdialog/dialog.h:128: error
- C#操作EXCEL
- CVTE2015校招Web后台西安站笔试题(回忆版)
- uva 757(贪心)
- lua查找表元素方法