触摸事件总结

来源:互联网 发布:app教育收费软件 编辑:程序博客网 时间:2024/05/19 13:07

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 
0 0