您的位置:首页 > 其它

触摸事件总结

2016-01-24 18:47 204 查看

1.触摸事件常用方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
//返回手指当前所在的位置。
- (CGPoint)locationInView:(UIView *)view;
//返回前一个触摸点的位置
- (CGPoint)previousLocationInView:(UIView *)view;


2.UITouch的一些属性

//触摸产生时所处的窗口
@property(nonatomic,readonly,retain) UIWindow    *window;

//触摸产生时所处的视图
@property(nonatomic,readonly,retain) UIView      *view;

//短时间内点按屏幕的次数,可以根据tapCount判断单击、双击或更多的点击
@property(nonatomic,readonly) NSUInteger          tapCount;

//记录了触摸事件产生或变化时的时间,单位是秒
@property(nonatomic,readonly) NSTimeInterval      timestamp;

//当前触摸事件所处的状态
@property(nonatomic,readonly) UITouchPhase        phase;


3.UIEvent属性

事件类型
@property(nonatomic,readonly) UIEventType     type;
@property(nonatomic,readonly) UIEventSubtype  subtype;

事件产生的时间
@property(nonatomic,readonly) NSTimeInterval  timestamp;


4.利用Category对UIView进行方法扩展,实现截屏功能:

#import "UIImage+YF.h"

@implementation UIImage (YF)//这是一种语法,是对某个类方法的扩充。
+ (instancetype)captureWithView:(UIView *)view
{
// 1.开启上下文
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);

// 2.将控制器view的layer渲染到上下文
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

// 3.取出图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

// 4.结束上下文
UIGraphicsEndImageContext();

return newImage;
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: