滚动控件到指定位置(:scrollToPoint)
函数
obj:scrollToPoint(横向偏移, 纵向偏移)
参数
- 横向偏移 浮点型
- 纵向偏移 浮点型
说明
该函数可以将 UIScrollView 及其子类 如(UITableView,UICollectionView,UIWebView ,WKWebView) 滚动到指定的位置
此方法只能在 2.3.0以上版本中使用
示例
local node = nodeView.matchForMainWindow(function (info) -- 匹配出应用中 UITableView
return info.superClass == "UITableView"
end ,true)
if (node) then
node[1]:scrollToPoint(0,1000) -- 滚动 1000px UITableView 中没有横坐标 所以这里 横坐标设置为0
sys.msleep(2000)
node[1]:scrollToPoint(0,-1000) --滚动到顶部
sys.msleep(2000)
node[1]:scrollToPoint(0,111000) --滚动到底部
end
--某短视频平台 播放下一个视频
local node = nodeView.matchForMainWindow(function (info) -- 匹配出应用中 UITableView
return info.superClass == "UITableView" and info.class == "AWEFeedTableView"
end ,true)
local _, y = node[1]:scrollCurrPoint() -- 获取当前可滚动视图节点 y轴
node[1]:scrollToPoint(0, y + 729) -- 滚动到下一个视频
--这里的 729 是经过两次获取 scrollCurrPoint 的y轴相减得到
node[1]:scrollToPoint(0, y - 729) -- 滚动到上一个视频