ios13防止下拉tableView滚动到顶部以消除工作表样式模态呈现的viewController [英] ios13 prevent pulling down on tableView which is scrolled to top from dismissing sheet style modally presented viewController

查看:170
本文介绍了ios13防止下拉tableView滚动到顶部以消除工作表样式模态呈现的viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tableViewController,它以默认的工作表样式呈现方式呈现.

I have a tableViewController which is presented modally with the default sheet style presentation.

我想保留这种模式样式,因为它看起来不错,并且在我的应用程序中也能很好地工作.而且我喜欢在下拉导航栏时的关闭.但是我不希望在tableView已经滚动到顶部时下拉tableView单元格,以使tableViewController被关闭.

I want to keep this modal style as it looks good and works well in my app. And I like the dismiss when pulling down on the navigation bar. However what I don't want is pulling down on the tableView cells to cause the tableViewController to be dismissed when the tableView is already scrolled to the top.

是否存在抑制这种行为但保持工作表样式模态表示的方式?我希望对tableView进行下拉以保持垂直反弹效果,而仅通过下拉导航栏部分才能通过平移来消除模态呈现的tableViewController.

Is there anyway to inhibit this behaviors but keep the sheet style modal presentation? I want the pull down on the tableView to keep the vertical bounce effect and only to be able to dismiss the modally presented tableViewController through pan by pulling down on the navigation bar portion.

推荐答案

当用户开始在表视图上拖动时,可以通过在表视图控制器上将isModalInPresentation设置为true来禁用强制删除行为. ,然后在停止拖动时将其重置为false,就像这样:

You can disable the pull-to-dismiss behavior by setting isModalInPresentation to true on your table view controller when the user begins dragging on the table view, and then reset it back to false when they stop dragging, like so:

class YourTableViewController: UITableViewController {
    override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        isModalInPresentation = true
    }

    override func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        isModalInPresentation = false
    }
}

请注意,您仍然可以稍微下拉您的表视图控制器,但是至少您不能完全将其关闭.而且,由于在拖动停止时将值重新设置为false,因此您可以通过在导航栏上向下拖动来取消设置.

Note that you'll still be able to slightly pull down your table view controller, but at least you won't be able to dismiss it entirely. And since the value is set back to false when dragging stops, you'll be able to dismiss by pulling down on the navigation bar.

此外,如果在表视图中添加UIRefreshControl,则在下拉到表视图时,它会禁用拉到关闭"行为.

Also, if you add a UIRefreshControl to your table view, it disables the pull-to-dismiss behavior when pulling down on the table view.

这篇关于ios13防止下拉tableView滚动到顶部以消除工作表样式模态呈现的viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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