ios – 如何检测touchesBegan,touchesMoved,touchesEnded来自另一个类的事件

ios – 如何检测touchesBegan,touchesMoved,touchesEnded来自另一个类的事件,第1张

概述我需要使用触摸事件,但我试图从另一个类中检测到它,所以如果触摸或移动等我将回到我的主类. 我首先在我的主类中调用“classTouchEvents”中的init方法 objectTouchEvents=[[classTouchEvents alloc]initWith:self.view]; 这是initWith“classTouchEvents”的方法 - (id)initWith:(UIVie 我需要使用触摸事件,但我试图从另一个类中检测到它,所以如果触摸或移动等我将回到我的主类.
我首先在我的主类中调用“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");}

但我无法得到关于触摸的任何日志.我需要一些帮助.
提前致谢.

解决方法 我将使用委托实现UIVIEw的自定义子类.

@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来自另一个类的事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1007035.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存