iPhone:获取可可触摸屏上的可点击区域列表

问题描述:

我有一个iPhone应用程序,我想要获取用户可点击的共同列表。我想自动化测试,并有一个客户端应用程序在屏幕上点击,但只是选择随机坐标并不理想,所以肯定可以点击的坐标列表会更好。iPhone:获取可可触摸屏上的可点击区域列表

到目前为止,我有这是顶层窗口通过视图:

getSubViewsCoords:(UIView *)view { 

iAppDelegate* appDelegate = [[UIApplication sharedApplication] delegate]; 


for (UIView *tempView in [view subviews]) { 

    // check if view responds to touch i.e. is an interactive view. 

    // go up through responder chain 
    // check if it reacts 
    // if it does then add to the gorilla's list 

    UIView *responderObj = tempView; 

    while (responderObj = [responderObj nextResponder]) { 

     if([responderObj respondsToSelector:@selector(touchesBegan:withEvent:)]){ 

      // get xy etc and add to instance var 
      //then recall this function 

      // convert to top level windows co-ordinate system. 
      CGRect viewRect = [tempView convertRect:[tempView bounds] toView:nil]; 

      clickableAreas = [clickableAreas stringByAppendingString: NSStringFromCGRect(viewRect)]; 
      clickableAreas = [clickableAreas stringByAppendingString: @"\n"]; 

      break; 


     } 

    } 

    [self getSubViewsCoords:tempView]; 

这是正确的方式去吗?有没有更简单的方法来获取这些信息?

在此先感谢您的帮助。

如果您还没有阅读过,您可能会发现这篇文章有帮助,Automated user interface testing on the iPhone