gpt4 book ai didi

ios - 如何检测 UIview 失去焦点或在 swift 4 中获得焦点?

转载 作者:行者123 更新时间:2023-11-28 05:38:21 33 4
gpt4 key购买 nike

我正在开发一个 ScrollView 页面,其中有一些使用 YoutubeKit 框架的 youtube 视频。

YoutubeKit 使用 UIView 来显示视频。我想在 UIView 未聚焦时暂停视频(未显示但用户显示)。

isfocused() 正在工作,但我想获得“一个事件”,以便在失去焦点时自动使用react。

我知道我需要创建一个自定义 UIview 类来覆盖 canBecomeFocused

这是我创建的自定义类的代码

import Foundation
import UIKit

class focusableUIview: UIView {
override var canBecomeFocused: Bool {
return true
}
override func didUpdateFocus(in context: UIFocusUpdateContext, withcoordinator: UIFocusAnimationCoordinator) {

print("focus")
}
}

我还更新了关于更改 UIView 类的 Storyboard,我想检测焦点变化。

我在质疑什么,我需要在 UIviewcontroller 类中做什么,我注意到 canBecomeFocused 从未被调用过...

我有点迷路了。非常感谢您的帮助

最佳答案

让你的 View 可聚焦

override var canBecomeFocused: Bool {
return true
}

然后覆盖此函数以获取焦点更新

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {

}

关于ios - 如何检测 UIview 失去焦点或在 swift 4 中获得焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57801944/

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