iOS 事件處理之UIResponder簡介,iosuiresponder

來源:互聯網
上載者:User

iOS 事件處理之UIResponder簡介,iosuiresponder

  • 在使用者使用app過程中,會產生各種各樣的事件
  • iOS中的事件可以分為3大類型:觸摸事件、加速計事件、遠端控制事件
  • 在iOS中不是任何對象都能處理事件,只有繼承了UIResponder的對象才能接收並處理事件。我們稱之為“響應者對象”
  • UIApplication、UIViewController、UIView都繼承自UIResponder,因此它們都是響應者對象,都能夠接收並處理事件

 

// 當手指開始觸摸view// NSArray,字典,NSSet(無序)- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    NSLog(@"%ld", touches.count);    NSLog(@"%s",__func__);}// 當手指在view上移動的時候- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{    NSLog(@"%s",__func__);        // 擷取UITouch對象    UITouch *touch = [touches anyObject];        // 擷取當前點    CGPoint curP = [touch locationInView:self];        // 擷取上一個點    CGPoint preP = [touch previousLocationInView:self];        // 擷取x軸位移量    CGFloat offsetX = curP.x - preP.x;        // 擷取y軸位移量    CGFloat offsetY = curP.y - preP.y;        // 修改view的位置(frame,center,transform)    self.transform = CGAffineTransformTranslate(self.transform, offsetX, offsetY);   //    self.transform = CGAffineTransformMakeTranslation(offsetX, 0);    }// 當手指離開這個view的時候- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{     NSLog(@"%s",__func__);}// 當觸摸事件被打斷的時候調用(電話打入)- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{    NSLog(@"%s",__func__);}

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.