gpt4 book ai didi

ios - TabBarController 中的转换 View 会中断 TouchMoved

转载 作者:行者123 更新时间:2023-11-30 13:34:43 25 4
gpt4 key购买 nike

我似乎在进行以下设置时遇到了一些问题:

  • 我有一个 UILongPressGestureRecognizer 的子类(import
    UIKit.UIGestureRecognizerSubclass
    ) 以便覆盖触摸移动
  • 我有一个包含此对象的按钮GestureRecognizer 子类,它调用选择器。
  • 此选择器调用的方法包含每次调用 touchesMoved 时由原始 GestureRecognizer 子类调用的回调。

因此,当我长按按钮,然后移动手指时,回调会被多次调用,我可以查看触摸的属性,例如数字。 (touches.count)

我正在尝试根据触摸信息转换 TabBarController 的 View Controller ,但是当我实现此操作时(通过 selectedIndex =UIView.transitionFromView())仅在 longPressEvent 开始时调用回调。 (即仅一次,而不是多次。)我不确定为什么会发生这种情况。由于按钮位于 TabBarController 中,因此它不应受到 View 转换的影响。

以下是一些相关代码:

GestureRecognizer 子类:

import UIKit.UIGestureRecognizerSubclass

class LongPressGestureRecongnizerSubclass: UILongPressGestureRecognizer{
var detectTouchesMoved = false
var toCallWhenTouchesMoved: ((touches: Set<UITouch>) -> ())?
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent) {
if detectTouchesMoved{
toCallWhenTouchesMoved?(touches: touches)
}

}
}

识别长按时调用的委托(delegate)方法。

func centerButtonLongPressed(tabBarView: TabBarView!){
for gestureRecognizer in tabBarView.centerButton.gestureRecognizers!{
if let longPressGestureRecognizer = gestureRecognizer as? LongPressGestureRecongnizerSubclass{
longPressGestureRecognizer.detectTouchesMoved = true
longPressGestureRecognizer.toCallWhenTouchesMoved = ({(touches: Set<UITouch>) -> (Void) in
//Here I can view touches properties every time touchesMoved() is called, but not when I try to transition view here.
})
}
}
}

更新:

我意识到问题在于,由于转换是同步调用的,因此它与 touchesMoved() 相混淆。当我将转换方法移出 UI 线程时,会引发以下错误:

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

如何防止缓慢的同步转换代码与 touchesMoved() 发生冲突?

我怎样才能实现我的设想?谢谢你的帮助。

最佳答案

我意识到动画中断触摸没有问题。触摸被取消,因为我不正确地使用自定义 UITabBarController FoldingTabBar,可以在 here 找到它。

关于ios - TabBarController 中的转换 View 会中断 TouchMoved,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36212550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com