UIScrollView touch event for IOS Learning

Source: Internet
Author: User

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:

 
 
  1. #import <Foundation/Foundation.h> 
  2.  
  3. @protocol ImageTouchDelegate  
  4. -(void)imageTouch:(NSSet *)touches withEvent:(UIEvent *)event whichView:(id)imageView;  
  5. @end  
  6.  
  7. @interface ImageTouchView : UIImageView   
  8. {  
  9.         id<ImageTouchDelegate>  delegate;  
  10.         BOOL delegatrue;  
  11. }  
  12. @property(nonatomic,assign)id<ImageTouchDelegate> delegate;  
  13. @end 

This is the header file. The source file can be like this.

 
 
  1. @implementation ImageTouchView  
  2. @synthesize     delegate;  
  3. -(id)initWithFrame:(CGRect)frame  
  4. {  
  5.         if (self == [super initWithFrame:frame])   
  6.         {  
  7.                 [self setUserInteractionEnabled:YES];  
  8.                 delegatrue=YES;  
  9.         }  
  10.         return  self;  
  11. }  
  12. - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view  
  13. {  
  14.         return YES;  
  15. }  
  16. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  
  17. {  
  18.         if (delegatrue)  
  19.         {  
  20.                 [delegate imageTouch:touches withEvent:event whichView:self];  
  21.         }   

Summary:IOSLearningUIScrollView TouchTouchEventI hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.