自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

UIScrollView不能響應UITouch事件的解決辦法

移動開發(fā) iOS
UIScrollView不能響應UITouch事件?讓UIScrollView將事件傳遞過去。于是最簡單的解決辦法就是加一個UIScrollView的category。這樣每個用到UIScrollView的地方只要導入這個category就可以直接響應相關的touch事件了。

這個不用多說直接上代碼。

原因是:UIView的touch事件被UIScrollView捕獲了。

解決辦法:讓UIScrollView將事件傳遞過去。于是最簡單的解決辦法就是加一個UIScrollView的category。這樣每個用到UIScrollView的地方只要導入這個category就可以直接響應相關的touch事件了。

類似問題:在論壇看見很多人說UIImageView也沒辦法響應,我沒嘗試過,不過我想解決辦法和原因都是一樣的。 如果有人嘗試過,不一樣,歡迎批評指正。

  1. #import "UIScrollView+UITouch.h"       
  2.  @implementation UIScrollView (UITouch)       
  3.  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {   
  4.    [[self nextResponder] touchesBegan:touches withEvent:event];   
  5.    [super touchesBegan:touches withEvent:event];   
  6.  }       
  7.  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {   
  8.    [[self nextResponder] touchesMoved:touches withEvent:event];   
  9.    [super touchesMoved:touches withEvent:event];   
  10.  }   
  11.  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {   
  12.    [[self nextResponder] touchesEnded:touches withEvent:event];   
  13.    [super touchesEnded:touches withEvent:event];   
  14.  }   
  15.  @end  
責任編輯:閆佳明 來源: oschina
相關推薦

2015-11-30 12:02:25

DNS服務器

2009-06-03 16:41:21

Eclipse亂碼Eclipse

2011-03-04 13:07:47

Filezilla

2013-08-13 14:08:23

android 4.0WebView

2010-04-16 12:42:44

無線路由器故障

2011-01-19 17:54:48

2009-05-31 09:07:35

Oracle鎖定

2016-03-23 09:37:22

響應式網(wǎng)頁設計

2015-03-23 11:16:38

網(wǎng)頁打不開

2011-06-17 11:10:51

Qt 中文 輸出

2009-12-07 18:38:16

WCF異常

2010-01-15 09:38:08

磁盤被寫保護解決辦法

2017-05-04 20:15:51

iOSNSTimer循環(huán)引用

2009-02-18 09:30:10

AJAX跨域XML

2020-05-09 10:59:33

git cloneLinux文件

2009-12-03 17:36:02

PHP Date()出

2009-11-30 10:55:16

PHP頁面亂碼

2009-05-26 14:34:55

Ubuntuwubi臨時

2011-04-21 16:42:40

傳真機

2012-03-14 10:58:27

Java
點贊
收藏

51CTO技術(shù)棧公眾號