李程站 发表于 2013-2-4 02:28:20

IOS学习之UIScrollView touch触摸事件

IOS学习之UIScrollView touch触摸事件是本文要介绍的内容,UIScrollView本身无法处理touch事件。要想实现,必须对UIScrollView上的subView做touch处理原理十分简单,好比要响应scrollView上的UIImageView,那么请创建一个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 == )   
[*]      {
[*]                ;
[*]                delegatrue=YES;
[*]      }
[*]      returnself;
[*]}
[*]- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
[*]{
[*]      return YES;
[*]}
[*]-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
[*]{
[*]      if (delegatrue)
[*]      {
[*]                ;
[*]      }   
小结:IOS学习之UIScrollView touch触摸事件的内容介绍完了,希望本文对你有所帮助!
【编辑推荐】

[*]iPhone人机界面常见任务处理方法之事件处理 (2)
[*]浅析在iPhone下实现UIScrollView图片浏览器功能
[*]iPhone开发指南之事件处理介绍
[*]关于Cocoa Touch那些问题
[*]了解iPhone应用中UIScrollView的使用方法
页: [1]
查看完整版本: IOS学习之UIScrollView touch触摸事件