UITouch詳解,uitouch
UITouch 對象用於位置、 大小、 運動和一根手指在螢幕上為某一特定事件的力度。觸摸的力度是從開始在 iOS 9 支援 3D 的觸摸的裝置上可用。你可以通過UIEvent對象傳遞給響應者對象訪問。一個UITouch對象包括訪問器:
引起觸摸的視圖或Window.
@property(nullable,nonatomic,readonly,strong) UIWindow *window
@property(nullable,nonatomic,readonly,strong) UIView *view
觸摸在視圖或Window的位置座標.
- (CGPoint)locationInView:(nullable UIView *)view
觸摸的半徑.
@property(nonatomic,readonly) CGFloat altitudeAngle
觸摸的力度(支援iOS9.0以上)
@property(nonatomic,readonly) CGFloat force
UITouch對象還包含一個指示觸摸發生時間的時間戳記,一個整數表示使用者點擊螢幕的次數,在觸摸階段以常量的形式描述觸摸是否開始,移動,或結束,或者是否為系統取消觸摸。
一個觸摸對象始終存留一個觸摸序列。處理事件時,永遠不會保留一個觸摸對象。如果你需要從一個觸摸階段到另一個階段保留有關觸摸資訊,就應該複製該資訊。
觸摸的 gestureRecognizers 屬性包含當前正在處理的觸摸手勢辨識器。每個手勢辨識器是 UIGestureRecognizer 具體子類的一個執行個體。
下面是一個執行個體
我在ViewController定義2個UIVIEW執行個體對象
@interface ViewController : UIViewController@property (nonatomic, strong) UIView *viewA;@property (nonatomic, strong) UIView *viewB;@end
然後
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.viewA =[[UIView alloc] initWithFrame:CGRectMake(10, 30, 48, 48)];
self.viewA.backgroundColor = [UIColor blackColor];
[self.view addSubview:self.viewA];
self.viewB =[[UIView alloc] initWithFrame:CGRectMake(10, 100, 48, 48)];
self.viewB.backgroundColor = [UIColor redColor];
[self.view addSubview:self.viewB];
NSLog(@"viewA:%@ \n viewB:%@ \n window:%@",self.viewA,self.viewB,[[[UIApplication sharedApplication] windows] objectAtIndex:0]);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// NSLog(@"%@",[touches anyObject]);
UITouch *touctObj = [touches anyObject];
NSLog(@"touch:%@ \n view:%@ \n window:%@",touctObj,[touctObj view],[touctObj window]);
}
觸摸以外地區我們可以看到view不是viewa也不是viewb,它是控制器的view.window是應用程式的window.
總之,UITouch對象包含一些發生觸摸的資訊。引起觸摸的視圖或window。