3d 触摸快速动作调用 UIButton
Posted
技术标签:
【中文标题】3d 触摸快速动作调用 UIButton【英文标题】:3d touch quick action call UIButton 【发布时间】:2016-12-22 12:54:58 【问题描述】:我在初始 VC 上创建了一个有 4 个 UIButtons 的应用程序。 每个按钮都连接到另一个 VC(在所有情况下都相同),但参数不同。
@IBAction func googleBtnPressed(_ sender: AnyObject)
searchEngine = "Google"
print(searchEngine)
performSegue(withIdentifier: "google", sender: nil)
@IBAction func bingBtnPressed(_ sender: AnyObject)
searchEngine = "Bing"
print(searchEngine)
performSegue(withIdentifier: "google", sender: nil)
@IBAction func ddgBtnPressed(_ sender: AnyObject)
searchEngine = "DuckDuckGo"
print(searchEngine)
performSegue(withIdentifier: "google", sender: nil)
@IBAction func customBtnPressed(_ sender: AnyObject)
performSegue(withIdentifier: "custom", sender: nil)
if let vc = segue.destination as? ViewController
if searchEngine == "Google"
vc.url = NSURL(string: "https://www.google.com")
vc.segueUsed = "google"
vc.searchEngine = "google"
else if searchEngine == "Bing"
vc.url = NSURL(string: "https://www.bing.com")
vc.segueUsed = "google"
vc.searchEngine = "bing"
else if searchEngine == "DuckDuckGo"
vc.url = NSURL(string: "https://www.duckduckgo.com")
vc.segueUsed = "google"
vc.searchEngine = "duckduckgo"
else if segue.identifier == "custom"
print(segue.identifier!)
if let vc = segue.destination as? ViewController
vc.segueUsed = "custom"
我想使用 3d Touch 的快速操作从主屏幕调用这 4 个按钮。 我已经在 info.plist 文件中创建了条目,但是在处理 AppDelegate.swift
中的响应时遇到了困难<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemType</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).Google</string>
<key>UIApplicationShortcutItemTitle</key>
<string>Google</string>
<key>UIApplicationShortcutItemIconType</key>
<string>google</string>
</dict>
</array>
我该如何实现?
感谢您的帮助。
【问题讨论】:
【参考方案1】:let yourViewcontroller = self.window?.rootViewController// This view controller should be action view controller
let itemKey = shortcutItem.userInfo["<YOUR KEY>"]
if itemKey == "Google"
//call google action method
else if itemKey == "Bing"
//call Bing action method
else if itemKey == "Ddg"
//call "Ddg" action method
else if itemKey == "CustomButton"
//call CustomButton action method
注意:您可以将 itemKey 保存在 ShortCutItemDictionary 中。
【讨论】:
能否详细说明如何从 appDelegate 调用操作方法。以上是关于3d 触摸快速动作调用 UIButton的主要内容,如果未能解决你的问题,请参考以下文章