【问题标题】:Swipe back gesture doesn't work on iOS with ScrollableView在带有 ScrollableView 的 iOS 上,向后滑动手势不起作用
【发布时间】:2016-12-24 13:07:59
【问题描述】:

我正在使用带有 SDK 5.4.0GA 的 Appcelerator Studio 4.7。

我想使用向后滑动手势返回上一个视图控制器,但我的触摸只是移动了ScrollableView 视图,即使我在屏幕左边缘开始手势。如果没有结束,则向后滑动手势可以正常工作ScrollableView

当我使用 Titanium Studio 3.4 时一切都很好。暂时无法使用,因为不支持,甚至无法登录。

这个问题是因为 Appcelerator Studio,而不是因为 SDK 版本。我曾尝试使用具有相同 SDK 版本的 Titanium Studio 和 Appcelerator Studio,但只有 Appcelerator Studio 有此问题。这就是我一年前坚持使用 Titanium Studio 的原因,但现在不可能了。

这里是没有解决的相关话题:https://archive.appcelerator.com/topic/581/swipe-right-from-the-edge-to-go-back-to-the-previous-window-doesn-t-work-anymore-in-ios-using-sdk-3-5-1-ga-and-4-0-0-ga/4

编辑。如何在 2 分钟内重现它:

1) 文件->新建->移动应用项目->默认合金项目

2) 添加名为 scrollable 的新控制器

scrollable.xml:

<Alloy>
    <Window class="container">
        <ScrollableView>
            <ScrollView>
                <View height="5000" backgroundColor="#DBD6D6">
                    <Label top="20">View1</Label>
                </View>
            </ScrollView>
            <ScrollView>
                <View height="5000" backgroundColor="#FED2FB">
                    <Label top="20">View2</Label>
                </View>
            </ScrollView>
            <ScrollView>
                <View height="5000" backgroundColor="#DCEFD7">
                    <Label top="20">View3</Label>
                </View>
            </ScrollView>
        </ScrollableView>
    </Window>
</Alloy>

index.js:

function doClick(e) {
    var scrollableController = Alloy.createController('scrollable',{
    });

    var view = scrollableController.getView();
    $.index.openWindow(view);
}

$.index.open();

index.xml:

<Alloy>
    <NavigationWindow>
        <Window class="container" id="index">
            <Label id="label" onClick="doClick">Press me</Label>
        </Window>
    </NavigationWindow>
</Alloy>

3) 就是这样!

【问题讨论】:

    标签: ios titanium appcelerator appcelerator-titanium appcelerator-alloy


    【解决方案1】:

    首先,我在 Appcelerator Studio 上尝试过您的代码,所以我不确定 Titanium Studio 在这种情况下会发生什么。

    现在,由于 Ti.UI.Window swipeToClose 属性直到 Ti SDK 5.2.0.GA 才存在,所以您可以确定它是否真的存在Studio 错误或 SDK 功能。我确信这不是问题,而只是误解。

    根据您的查询,有两种方法(据我所知)提供 滑动到上一个窗口(比如说 SPW) 功能以及 Scrollable 功能,即在 ScrollableView 和它的父视图之间留下一些填充,如下所示:

    -方法一-

    <Alloy>
        <Window class="container" backgroundColor="white">
            <ScrollableView backgroundColor="blue" clipViews="false" left="20" right="20">
                <View backgroundColor="red">
                    <Label>View1</Label>
                </View>
                <View backgroundColor="green">
                    <Label>View2</Label>
                </View>
                <View backgroundColor="cyan">
                    <Label>View3</Label>
                </View>
            </ScrollableView>
        </Window>
    </Alloy>
    

    这些是我在您的代码中所做的更改:

    • 添加了 20dp 的左右内边距,这将启用 SPW 功能,但 ScrollableView 的宽度会更小。
    • 设置 clipViews 属性以显示相邻视图以获得更好的 UI。如果您将此属性设置为 true,则 SPW 功能也会起作用。

    -方法 2- 只有在您知道 ScrollableView 的确切尺寸时使用 hitRect property

    // replace the line in Method 1 with this one and apply the tss on it
    <ScrollableView backgroundColor="blue" id="SC">
    

    scrollable.tss

       "#SC" : {
            // (x,y) is top-left corner of hitRect and height/width will determine its dimension where user can swipe the scrollable view
            // on remaining area, you can perform SPW feature 
            hitRect : {
                x : 100,
                y : 100,
                height : 200,   
                width : 200    
            }
        }
    

    既然您已经了解了实现这两个功能的两种方式,我希望它对您有用。

    【讨论】:

    • 我之前尝试过这两种方法,但它们有一个缺点:视图不接受屏幕左边缘的触摸事件。例如,用户通过在屏幕边缘滑动来向下滚动视图是很常见的,使用这两种方法是行不通的。我已更新 scrollable.xml 以显示此问题。此外,您可以在 App Store 中打开任何应用页面,并看到您可以水平滚动屏幕截图,但所有其他手势都可用。再一次,在 Titanium Studio 3.4 中,一切都像魅力一样运行,没有任何黑客攻击。
    • 那么我认为您将不得不禁用 SPW 功能,因为我在此功能上也遇到了一些 UI 问题。
    猜你喜欢
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多