iPhone自定义类/响应链中的对象 [英] iPhone Custom Class / Object in Responder Chain

查看:39
本文介绍了iPhone自定义类/响应链中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将自定义类添加到响应者链的策略,最佳实践和解决方案.这是因为我意识到我在几个不同的应用程序中以相同的方式处理触摸事件.为了使生活更轻松,我想将功能转移到自定义类中,并让该类成为触摸事件的第一响应者.由于我最初的几个想法没有用,所以我意识到这不是我可以解决的临时问题.

I am looking for strategies, best practices and solutions to adding a custom class to the responder chain. This came about because I realized I was handling touch events the same way in several different applications. To make life easy, I wanted to move the functionality into a custom class and have that class become the first responder for touch events. Since my first several ideas did not work, I realized this wasn't going to be an ad-hoc issue I could address.

我已经根据阅读的不同文档,帖子等进行了几次尝试(这就是为什么我现在不发布源代码).我最近的尝试是从UIResponder派生的,并且有一个UIView成员,该成员存储指向当前视图的指针.

I have made several attempts based on different documents, posts, etc that I have read (which is why I'm not posting source right now). My most recent attempt derives from UIResponder and has a UIView member that stores a pointer to the current view.

在我花太多时间来弄清楚"之前,我想看看是否有人有任何想法.

Before I spent too much time on 'figuring it out', I wanted to see if anyone had any ideas.

所以我的问题是如何添加自定义类作为第一响应者,特别是为了接收触摸事件"?

So my question is 'how do I add a custom class to be the first responder, specifically to receive touch events'?

推荐答案

您的解决方案听起来很奇怪,因为UIView本身就是UIResponder.

Your solution sounds weird because UIView is itself a UIResponder.

如果您具有通用的事件处理代码,为什么不在UIView或UIResponder上声明一个类别,然后您便可以从所有UIView(或UIResponder)子类(包括UIApplication,UIWindow和UIControl)中访问该类别.

If you have common event handling code, why not declare a category on UIView or UIResponder which you will then be able to access from all of your UIView (or UIResponder) subclasses including UIApplication, UIWindow and UIControl.

这篇关于iPhone自定义类/响应链中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆