gpt4 book ai didi

ios - 当 applicationWillEnterForeground 发生时验证剪贴板(快速)

转载 作者:行者123 更新时间:2023-11-30 14:07:47 24 4
gpt4 key购买 nike

我正在构建一个应用程序,允许将图像从 safari 搜索复制到 ImageView ,当我重新打开应用程序时,如果我处于特定 View (下图),我需要验证剪贴板是否是不为空我想启用粘贴按钮。 enter image description here

我想知道如何快速做到这一点。

再次感谢。

最佳答案

您可以像这样检查剪贴板上的图像:

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if UIPasteboard.generalPasteboard().image != nil {
pasteButton.enabled = true
}
else {
pasteButton.enabled = false
}
}

如果你想使用该事件,你可以这样做:

override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self,
selector: Selector("updatePasteButton"),
name: UIApplicationWillEnterForegroundNotification,
object: nil)
}

func updatePasteButton() {
if UIPasteboard.generalPasteboard().image != nil {
pasteButton.enabled = true
}
else {
pasteButton.enabled = false
}
}

每次事件发生时都会调用 updatePasteButton()。

关于ios - 当 applicationWillEnterForeground 发生时验证剪贴板(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141945/

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