XCode7 UITests如何测试屏幕边缘平移手势? [英] XCode7 UITests how to test screen edge pan gestures?

查看:86
本文介绍了XCode7 UITests如何测试屏幕边缘平移手势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有以下手势识别器.我已经看过xCode7 UI,看到它已经向上/向下/向左/向右滑动,但是没有平移或边缘平移手势.

I have the following gesture recognizer in my app. I've looked at xCode7 UI and see that it has swipe up/down/left/right, but no pan or edge pan gestures.

如何出于UITesting的目的测试或启动屏幕边缘平移手势?

  UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(show)];
    leftEdgeGesture.edges = UIRectEdgeLeft;
    leftEdgeGesture.delegate = self;
    [self.view addGestureRecognizer:leftEdgeGesture];

推荐答案

我花了一段时间试图弄清楚这一点,在元素层次结构中导航.大量的谷歌搜索,一无所获.

I spent a while trying to figure this out, navigating around the element hierarchy. Lots and lots of googling and finding nothing.

我放弃了两次,然后弄清楚了.

I gave up twice, then figured it out.

我们只需要在应用主屏幕上放置两个坐标,然后将其中一个拖动到另一个即可.

We just need two coords on the main app screen, and drag one to the other.

请客!

XCUIApplication *app = [[XCUIApplication alloc] init];
[app launch];

// Set a coordinate near the left-edge, we have to use normalized coords
// so you set using percentages, 1% in on the left, 15% down from the top
XCUICoordinate *coord1 = [app coordinateWithNormalizedOffset:CGVectorMake(0.01, 0.15)];

// Then second coordinate 40 points to the right
XCUICoordinate *coord2 = [coord1 coordinateWithOffset:CGVectorMake(40, 0)];

// Perform a drag from coord1 to coord2
// Simulating swipe in from left edge
[coord1 pressForDuration:0.5f thenDragToCoordinate:coord2];

希望这将帮助其他一直在努力模拟边缘滑动的人.

Hopefully this will help everyone else who has been struggling to simulate an edge swipe.

这篇关于XCode7 UITests如何测试屏幕边缘平移手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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