Calabash-ios有没有可能执行滚动,直到特定的ui元素显示在屏幕的中心,或者只滚动一些像素?
谢谢你!!
发布于 2014-03-28 14:55:43
这不是一个真正的答案,但你可以尝试在calabash-ios谷歌组https://groups.google.com/forum/#!forum/calabash-ios中提出这个问题。在这个组中,有一些非常有经验的人,他们有很多知识。
发布于 2015-05-12 00:37:31
默认情况下,Calabash不提供此功能;它可以滚动到UITableView项或UICollectionView项,但不能将UIScrollView滚动到任意视图。
所以我写了一些帮助器来做这件事。这段代码是用Xamarin.iOS编写的,但我相信您可以根据自己的喜好对其进行修改。
// Scrolls a given ScrollView a given amount. Doesn't check the amount.
void ScrollBy(AppResult scrollView, float amount)
{
app.DragCoordinates(
scrollView.Rect.CenterX, scrollView.Rect.CenterY + amount * 0.5f,
scrollView.Rect.CenterX, scrollView.Rect.CenterY - amount * 0.5f);
}
// Scrolls a given amount down (can be negative), paging the results
void ScrollDown(AppResult scrollView, float amount)
{
const float buffer = 50f;
var usefulRoom = scrollView.Rect.Height - buffer * 2;
var sign = Math.Sign(amount);
var distance = Math.Abs(amount);
while (distance > usefulRoom) {
ScrollBy(scrollView, usefulRoom * sign);
distance -= usefulRoom;
}
if (distance > 20f)
ScrollBy(scrollView, distance * sign);
}
// Scrolls a given UIScrollView to center on the given element
void ScrollToElement(AppResult scrollView, AppResult element)
{
var amount = element.Rect.CenterY - scrollView.Rect.CenterY;
ScrollDown(scrollView, amount);
}ScrollToElement是这里的主要调用。只需向它传递您想要滚动的ScrollView和它应该指向的元素。您可以使用buffer常量来调整每次轻扫所使用的ScrollView大小。
https://stackoverflow.com/questions/22660478
复制相似问题