IOSLearningUIScrollView touchTouchEventIs the content to be introduced in this article,UIScrollViewUnable to handleTouch event. To achieve this, you mustUIScrollViewSubView onTouchThe processing principle is very simple. For example, to respond to the UIImageView on the scrollView, create a subclass of UIImageVIew, which is processed by the custom UIImageView.Touch event.
The header file declaration is as follows for your reference:
- #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
This is the header file. The source file can be like this.
- @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];
- }
Summary:IOSLearningUIScrollView TouchTouchEventI hope this article will help you!