开发者

iPhone: Get a list of clickable areas on screen in cocoa touch

I have an iPhone app and I want to get a list of co-ords that are clickable by a user. I want to automate testing and have a client app click around on screen but just choosing random coords isn't ideal so a list of coords that are definitely clickable would be much better.

So far I have this the view passed in is top level window:

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 stringByAppend开发者_运维问答ingString: @"\n"];

            break;


        }

    }

    [self getSubViewsCoords:tempView];

Is this the correct way to go about it? Is there an easier way to get this information?

Thanks in advance for your help.


If you haven't already read it, you'll probably find this article helpful, Automated user interface testing on the iPhone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜