我首先在我的主类中调用“classtouchEvents”中的init方法
objecttouchEvents=[[classtouchEvents alloc]initWith:self.vIEw];
这是initWith“classtouchEvents”的方法
- (ID)initWith:(UIVIEw *)selfVIEw{ self = [super init]; if (self) { NSLog(@"here"); vIEw=[[UIVIEw alloc]init]; vIEw=selfVIEw; // Custom initialization } return self;}
我得到“这里”日志,所以我猜它正在工作,但我无法检测视图是否触摸或任何东西.这是我在classtouchEvents中的触摸事件
-(voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchBegan");}-(voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchmoved");}-(voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchended");}
但我无法得到关于触摸的任何日志.我需要一些帮助.
提前致谢.
@protocol touchEventsDelegate <NSObject>-(voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event inVIEw:(UIVIEw *)vIEw;-(voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event inVIEw:(UIVIEw *)vIEw;-(voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event inVIEw:(UIVIEw *)vIEw;@end@property (weak,nonatomic) ID<touchEventsDelegate> delegate;
在ClasstouchEvents中实现这些委托方法.
在自定义视图中实现触摸事件方法并调用委托.
-(voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (self.delegate && [self.delegate respondsToSelector:@selector(touchesBegan:withEventinVIEw)]) { [self.delegate touchesBegan:touches withEvent:event inVIEw:self]; }}总结
以上是内存溢出为你收集整理的ios – 如何检测touchesBegan,touchesMoved,touchesEnded来自另一个类的事件全部内容,希望文章能够帮你解决ios – 如何检测touchesBegan,touchesMoved,touchesEnded来自另一个类的事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)