首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Calabash-ios。有没有可能只对几个像素执行滚动?

Calabash-ios。有没有可能只对几个像素执行滚动?
EN

Stack Overflow用户
提问于 2014-03-26 20:05:07
回答 2查看 695关注 0票数 0

Calabash-ios有没有可能执行滚动,直到特定的ui元素显示在屏幕的中心,或者只滚动一些像素?

谢谢你!!

EN

回答 2

Stack Overflow用户

发布于 2014-03-28 14:55:43

这不是一个真正的答案,但你可以尝试在calabash-ios谷歌组https://groups.google.com/forum/#!forum/calabash-ios中提出这个问题。在这个组中,有一些非常有经验的人,他们有很多知识。

票数 0
EN

Stack Overflow用户

发布于 2015-05-12 00:37:31

默认情况下,Calabash不提供此功能;它可以滚动到UITableView项或UICollectionView项,但不能将UIScrollView滚动到任意视图。

所以我写了一些帮助器来做这件事。这段代码是用Xamarin.iOS编写的,但我相信您可以根据自己的喜好对其进行修改。

代码语言:javascript
复制
// 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大小。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22660478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档