我希望我的应用程序中有一个按钮,当按下它时,这个(见下图)弹出。我该怎么做?我不想创建自定义共享扩展,我只想要默认的。我应该使用什么代码?所有在线教程都是用Objective-C编写的。请用Swift给出答案。
图像:http://9to5mac.com/2014/06/30/hands-on-1password-beta-shows-off-ios-8s-touch-id-extensions-apis-video/#jp-carousel-330420 以下是我的代码,但我收到一个错误,即UIBarButtonItem无法转换为UIVIew。为什么?该操作连接到导航栏按钮项?
图像:http://9to5mac.com/2014/06/30/hands-on-1password-beta-shows-off-ios-8s-touch-id-extensions-apis-video/#jp-carousel-330420 以下是我的代码,但我收到一个错误,即UIBarButtonItem无法转换为UIVIew。为什么?该操作连接到导航栏按钮项?
@IBAction func ActionButton(sender: UIBarButtonItem) {
let firstActivityItem = "Text you want"
let secondActivityItem : NSURL = NSURL(string: "http//:urlyouwant")!
// If you want to put an image
let image : UIImage = UIImage(named: "TALogo")!
let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, secondActivityItem, image], applicationActivities: nil)
// This lines is for the popover you need to show in iPad
activityViewController.popoverPresentationController?.sourceView = (sender as! UIBarButtonItem)
// This line remove the arrow of the popover to show in iPad
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo
]
self.presentViewController(activityViewController, animated: true, completion: nil)
}
UIBarButtonItem
的情况下,popoverPresentationController
有一个名为barButtonItem
的属性。 - Victor Sigler