UITouch詳解,uitouch

來源:互聯網
上載者:User

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。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.