gpt4 book ai didi

ios - 每当激活带有链接的 TextView 时,应用程序就会崩溃并出现画外音

转载 作者:搜寻专家 更新时间:2023-10-30 23:09:03 26 4
gpt4 key购买 nike

堆栈跟踪:

* thread #1: tid = 0x1ee50f, 0x00000001096f5d05 libswiftFoundation.dylib`static Foundation.DateComponents._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSDateComponents>) -> Foundation.DateComponents with unmangled suffix "_merged" + 85, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #0: 0x00000001096f5d05 libswiftFoundation.dylib`static Foundation.DateComponents._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSDateComponents>) -> Foundation.DateComponents with unmangled suffix "_merged" + 85
frame #1: 0x000000010558e36f Invest`@objc InvestDashboard.textView(UITextView, shouldInteractWith : URL, in : _NSRange) -> Bool + 79 at InvestDashboard.swift:0
frame #2: 0x000000011fd478fc UIKit`-[UITextViewAccessibility accessibilityActivate] + 838
frame #3: 0x000000011fed29d2 UIAccessibility`-[NSObject(UIStorage) accessibilityPerformAction:withValue:fencePort:] + 1448
frame #4: 0x000000011feaa63d UIAccessibility`_performActionCallback + 163
frame #5: 0x000000011fc0cec4 AXRuntime`_AXXMIGPerformAction + 107
frame #6: 0x000000011fc06f06 AXRuntime`_XPerformAction + 216
frame #7: 0x000000011fc16541 AXRuntime`mshMIGPerform + 266
frame #8: 0x0000000106d1ff89 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
frame #9: 0x0000000106d1ff01 CoreFoundation`__CFRunLoopDoSource1 + 465
frame #10: 0x0000000106d18045 CoreFoundation`__CFRunLoopRun + 2389
frame #11: 0x0000000106d17494 CoreFoundation`CFRunLoopRunSpecific + 420
frame #12: 0x000000010cc38a6f GraphicsServices`GSEventRunModal + 161
frame #13: 0x00000001078c2964 UIKit`UIApplicationMain + 159
frame #14: 0x000000010467e99f InvestDemo`main + 111 at AppDelegate.swift:29
frame #15: 0x000000010b88268d libdyld.dylib`start + 1
frame #16: 0x000000010b88268d libdyld.dylib`start + 1

每当我在其中包含链接的 TextView 上使用 activate 时,就会发生这种情况。我已经尝试了很多不同的事情,比如重写 accessibilityActivate() -> Bool 但在调用此方法之前应用程序崩溃了。有什么建议吗?

最佳答案

我解决了这个问题并想分享,以便其他有同样令人困惑的问题的人可以解决它。

首先要做的是继承 UITextView 并在该子类中覆盖 func accessibilityActivate() -> Bool。然后创建一个委托(delegate)来处理激活 TextView 时发生的事情,并通过覆盖的方法调用它。

然后根据 UIAccessibilityIsVoiceOverRunning() 设置 TextView 的委托(delegate),因此如果语音正在运行,则将 UITextViewDelegate 设置为 nil防止崩溃发生,然后激活操作由您在上面的子类中覆盖的方法处理。最后,为UIAccessibilityVoiceOverStatusChanged设置一个监听器,设置从off到on时的UITextViewDelegatenil,并设置为原来的委托(delegate)类对于相反的情况。

部分代码:

//: Playground - noun: a place where people can play

import UIKit

class Test : UITabBarController, UITextViewDelegate, ActivationDelegate {

var voiceOverRunning : Bool {
get {
return UIAccessibilityIsVoiceOverRunning()
}
}

var testView = AccessibilityView()

override func viewDidLoad() {
if !voiceOverRunning {
testView.delegate = self
} else {
testView.activationDelegate = self
}

NotificationCenter.default.addObserver(
self,
selector: #selector(self.didChangeVoiceOver),
name: NSNotification.Name(rawValue: UIAccessibilityVoiceOverStatusChanged),
object: nil)
}

func doStuff() {
/*
Do what you want to happen here on activation
*/
}


@objc
func didChangeVoiceOver(){
testView.delegate = voiceOverRunning ? nil : self
testView.activationDelegate = voiceOverRunning ? self : nil
}


}

protocol ActivationDelegate : class {
func doStuff()
}
class AccessibilityView : UITextView {

var activationDelegate : ActivationDelegate!

override func accessibilityActivate() -> Bool {
activationDelegate.doStuff()
return true
}
}

关于ios - 每当激活带有链接的 TextView 时,应用程序就会崩溃并出现画外音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43189346/

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