IOS學習之UIScrollView touch觸摸事件
作者:佚名
UIScrollView本身無法處理touch事件。要想實現(xiàn),必須對UIScrollView上的subView做touch處理原理十分簡單,來看本文內容如何解決。
IOS學習之UIScrollView touch觸摸事件是本文要介紹的內容,UIScrollView本身無法處理touch事件。要想實現(xiàn),必須對UIScrollView上的subView做touch處理原理十分簡單,好比要響應scrollView上的UIImageView,那么請創(chuàng)建一個UIImageVIew的子類,由這個自定義的UIImageView來處理touch事件。
頭文件聲明如下,供參考:
- #import <Foundation/Foundation.h>
- @protocol ImageTouchDelegate
- -(void)imageTouch:(NSSet *)touches withEvent:(UIEvent *)event whichView:(id)imageView;
- @end
- @interface ImageTouchView : UIImageView
- {
- id<ImageTouchDelegate> delegate;
- BOOL delegatrue;
- }
- @property(nonatomic,assign)id<ImageTouchDelegate> delegate;
- @end
這個是頭文件,源文件可以是這個這樣子
- @implementation ImageTouchView
- @synthesize delegate;
- -(id)initWithFrame:(CGRect)frame
- {
- if (self == [super initWithFrame:frame])
- {
- [self setUserInteractionEnabled:YES];
- delegatrue=YES;
- }
- return self;
- }
- - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
- {
- return YES;
- }
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- {
- if (delegatrue)
- {
- [delegate imageTouch:touches withEvent:event whichView:self];
- }
小結:IOS學習之UIScrollView touch觸摸事件的內容介紹完了,希望本文對你有所幫助!
責任編輯:zhaolei
來源:
互聯(lián)網