IOS學(xué)習(xí)之UIScrollView touch觸摸事件
IOS學(xué)習(xí)之UIScrollView touch觸摸事件是本文要介紹的內(nèi)容,UIScrollView本身無法處理touch事件。要想實(shí)現(xiàn),必須對(duì)UIScrollView上的subView做touch處理原理十分簡單,好比要響應(yīng)scrollView上的UIImageView,那么請(qǐng)創(chuàng)建一個(gè)UIImageVIew的子類,由這個(gè)自定義的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
這個(gè)是頭文件,源文件可以是這個(gè)這樣子
- @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];
- }
小結(jié):IOS學(xué)習(xí)之UIScrollView touch觸摸事件的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!