我知道如何创建iOS共享扩展程序,但我能解释的是,是否有办法使其成为全屏幕,例如Action扩展程序?
Pinterest好像这样做,但我不确定如何。Action扩展的文档说使用:
<key>NSExtensionActionWantsFullScreenPresentation</key>
<true/>
在扩展程序的plist文件中,但这似乎在Share扩展名中没有效果?
无论如何要做到这一点?
答案 0 :(得分:5)
您可以从iOS Full Screen Share Extension获取提示,然后您可以找到以下代码段的更新语法,该语法与 Swift 3 和 Swift 4 <兼容/ p>
<强> EntryViewController 强>
import UIKit
@objc(EntryViewController)
class EntryViewController : UINavigationController {
override init(rootViewController: UIViewController) {
super.init(rootViewController: ShareViewController())
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.view.transform = CGAffineTransform(translationX: 0, y: self.view.frame.size.height)
UIView.animate(withDuration: 0.3, animations: { () -> Void in
self.view.transform = .identity
})
}
}
<强> ShareViewController 强>
import UIKit
import Social
class ShareViewController: SLComposeServiceViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
self.navigationItem.title = "Share"
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: Selector(("cancelButtonTapped:")))
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: Selector(("saveButtonTapped:")))
}
func saveButtonTapped(sender: UIBarButtonItem) {
self.hideExtensionWithCompletionHandler(completion: { (Bool) -> Void in
self.extensionContext!.completeRequest(returningItems: nil, completionHandler: nil)
})
}
func cancelButtonTapped(sender: UIBarButtonItem) {
self.hideExtensionWithCompletionHandler(completion: { (Bool) -> Void in
self.extensionContext!.cancelRequest(withError: NSError())
})
}
func hideExtensionWithCompletionHandler(completion: @escaping (Bool) -> Void) {
UIView.animate(withDuration: 0.3, animations: {
self.navigationController!.view.transform = CGAffineTransform(translationX: 0, y: self.navigationController!.view.frame.size.height)
}, completion: completion)
}
}
答案 1 :(得分:0)
我已经解决了全屏共享扩展。
很简单。
您添加NSExtensionActionWantsFullScreenPresentation并在扩展程序的info.plist的NSExtension下将TRUE设置