[英]Full screen iOS share Extension
I know how to create an iOS share extension, but what I can't figure out is if there is a way to make it fullscreen such as an Action extension?我知道如何创建 iOS 共享扩展,但我不知道是否有办法使其全屏,例如 Action 扩展?
Pinterest seem to do this but I'm not sure how. Pinterest 似乎这样做,但我不知道如何。
The docs for an Action extension say to use: Action 扩展的文档说要使用:
<key>NSExtensionActionWantsFullScreenPresentation</key>
<true/>
In the plist file for the extension but this doesn't seem to have an effect in the Share extension?在扩展名的 plist 文件中,但这似乎对共享扩展名没有影响?
Is there anyway to accomplish this?有没有办法做到这一点?
You can get ideas from there iOS Full Screen Share Extension and you can find the updated syntax for the code snippets below which is compatible with Swift 3 and Swift 4你可以从iOS Full Screen Share Extension那里得到想法,你可以找到下面与Swift 3和Swift 4兼容的代码片段的更新语法
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)
}
}
I have solved full screen share extension.我已经解决了全屏共享扩展。
It's simple.这很简单。
You add NSExtensionActionWantsFullScreenPresentation and set TRUE under NSExtension of extension app's info.plist您添加 NSExtensionActionWantsFullScreenPresentation 并在扩展应用程序的 info.plist 的 NSExtension 下设置 TRUE
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/AppExtensionKeys.html#//apple_ref/doc/uid/TP40014212-SW35 https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/AppExtensionKeys.html#//apple_ref/doc/uid/TP40014212-SW35
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.