全屏 iOS 分享扩展
Full screen iOS share Extension
我知道如何创建 iOS 共享扩展,但我想不通的是是否有办法让它全屏显示,例如 Action 扩展?
Pinterest 似乎是这样做的,但我不确定是怎么做到的。
Action 扩展的文档说要使用:
<key>NSExtensionActionWantsFullScreenPresentation</key>
<true/>
在扩展的 plist 文件中,但这似乎对共享扩展没有影响?
有没有办法做到这一点?
您可以从那里获得灵感 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)
}
}
我已经解决了全屏共享扩展。
很简单。
您添加 NSExtensionActionWantsFullScreenPresentation 并在扩展应用的 NSExtension 下设置 TRUE info.plist
我知道如何创建 iOS 共享扩展,但我想不通的是是否有办法让它全屏显示,例如 Action 扩展?
Pinterest 似乎是这样做的,但我不确定是怎么做到的。
Action 扩展的文档说要使用:
<key>NSExtensionActionWantsFullScreenPresentation</key>
<true/>
在扩展的 plist 文件中,但这似乎对共享扩展没有影响?
有没有办法做到这一点?
您可以从那里获得灵感 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)
}
}
我已经解决了全屏共享扩展。
很简单。
您添加 NSExtensionActionWantsFullScreenPresentation 并在扩展应用的 NSExtension 下设置 TRUE info.plist