【发布时间】:2026-01-03 20:50:01
【问题描述】:
所以我有一个名为 SettingsViewController 的 tableviewController,它有以下 touchesEnded 函数:
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
print("A")
super.touchesEnded(touches, with: event)
print("B")
if let touch = touches.first {
print("C")
let touchLocation = touch.location(in: view)
// 290 because the width of the view is 414, and the SettingsViewController width gets set to 0.7 * the view width in SlideInTransition. 0.7 * 414 is 289.8
if touchLocation.x > 290 {
dismiss(animated: true)
}
}
}
我做了 print 语句来查看它是否被调用,它不是。此视图控制器在自定义转换中呈现“菜单式”幻灯片。使用自定义转换显示的新 tablevc 的 UIView 的边界是否可能是问题所在?无论如何,我已经尝试实现 super.touchesEnded,或者添加所有覆盖触摸功能并在每次模拟时点击整个屏幕,但 touchesEnded 永远不会被调用。知道出了什么问题以及如何解决吗?谢谢
【问题讨论】:
-
您正在使用 "'menu-esque' slide in custom transition" 来展示您的
SettingsViewController...UITableViewController?您是否在该表格视图上获得标准触摸事件?行选择、滚动、与单元格内容 UI 元素的交互等? -
嗯,它使用的是静态单元格,因为我本质上只是将它用作设置选项卡。因此,您可以点击其中一个单元格中的按钮,但不能滚动、行选择等。
-
实际上这可能会产生误导,我可以点击一个只有标签的单元格并且单元格的边界线消失,我认为它已被选中。为什么呢?如果没有启用这些是问题吗?
-
您是通过代码创建控制器吗?还是在 Storyboard 中设计它们?
-
tableviewController 在我的故事板中,但在我的代码中使用字符串标识符实例化,在点击按钮时
标签: ios swift xcode uitableview touches