如何记录所有的用户的触摸在iPhone应用程序 [英] How to record all of the user's touches in iPhone app

查看:102
本文介绍了如何记录所有的用户的触摸在iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这是的扩展(和说明)一个问题我昨天问了。



我正在进行一个研究项目,我想在iPhone应用程序中记录所有的用户触摸。实验后,我将能够下载数据,并在Excel或(更可能的)Matlab中处理它,并确定他们点击某些按钮,当他们点击某些按钮等多少次。为此,我需要



a)他们触摸



b)他们感动的地方



c)他们触摸了哪个视图



前两个很容易,但第三个我有麻烦。我知道我可以做到这一点来获得被触摸的UIView的引用:

  CGPoint locationPoint = [[touches anyObject] locationInView :自]; 
UIView * viewYouWishToObtain = [self hitTest:locationPoint withEvent:event];

但是,这只会给我一个指向视图的指针,而不是视图的名称触摸。我可以为每个视图分配一个标签,但是每次我创建一个新的视图,我需要记住标记它(或者,初始化时记录每个视图的地址,并在视图被触摸时记录它)。子类化UIView和添加一个自动标签不是一个真正的选择,因为我创建其他UIButtons和UISliders,并需要子类,这也不是一个很好的解决方案。



有人知道一个干净,容易的方法吗?

解决方案

对于他们触及的视图,您需要什么信息?



也许你可以使用一个类别来添加一个方法到UIView。此方法将生成包含有关视图的信息的字符串。例如:




  • 其类型UIButton等。

  • 其大小和位置

  • 视图的标题(如果有)(例如按钮标题)

  • 父视图类型和标题

  • 其他内容,例如



例如:Type:UIButton Title:Back Rect:{3,5,40,25}或一些这样的字符串。



这很干净,给你相当多的信息。 / p>

note: This is an expansion (and clarification) of a question I asked yesterday.

I am conducting a research project where I want to record all of the user's touches in the iPhone app. After the experiment, I will be able to download the data and process it in either Excel or (more likely) Matlab and determine how many times they clicked on certain buttons, when they clicked certain buttons, etc. To do this, I would need to know:

a) When they touched

b) Where they touched

c) Which view they touched

The first two are easy, but the third I am having trouble with. I know I can do this to get the reference to the UIView that was touched:

CGPoint locationPoint = [[touches anyObject] locationInView:self];
UIView* viewYouWishToObtain = [self hitTest:locationPoint withEvent:event];

However, that will just give me a pointer to the view, not the name of the view that was touched. I could assign each view a tag, but then every time I create a new view I would need to remember to tag it (or, alternatively, log the address of each view when initialized and log it when the view is touched). Subclassing UIView and adding an automatic tag isn't really an option since I'm creating other UIButtons and UISliders and would need to subclass those also, which doesn't seem like a very good solution.

Does anyone know of a clean, easy way to do this? Thanks.

解决方案

For "Which view they touched", what information do you need?

Perhaps you could use a category to add a method to UIView. This method would generate a string containing information about the view. Such as:

  • its type e.g. UIButton etc.
  • its size and position
  • the title of the view, if it has one (e.g. the button title)
  • the parent view type and title
  • other stuff e.g. is the view enabled, what state it is in. anything you like.

For example: "Type:UIButton Title:"Back" Rect:{3,5,40,25}" or some such string.

This is very clean and gives you quite a lot of information to be going with.

这篇关于如何记录所有的用户的触摸在iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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