gpt4 book ai didi

ios - 如何在单击“取消”按钮时关闭 UIActivityViewController?

转载 作者:行者123 更新时间:2023-12-01 16:02:55 32 4
gpt4 key购买 nike

    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
let excludeActivities = [UIActivityTypeAirDrop, UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo,UIActivityTypeMail,UIActivityTypeOpenInIBooks,UIActivityTypeCopyToPasteboard]

activityVC.excludedActivityTypes=excludeActivities
let nav = UINavigationController(rootViewController: activityVC)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover
let popover = nav.popoverPresentationController as UIPopoverPresentationController!
activityVC.preferredContentSize = CGSizeMake(0,150)
popover.sourceView = self.view
popover.sourceRect = CGRectMake(345,580,0,0)
self.presentViewController(nav, animated: true, completion: nil)

我试图在单击取消按钮时关闭事件 Controller ,但这不起作用。单击 Controller 外部的任意位置时,此操作会被取消,但不会通过点击取消按钮来取消。

最佳答案

就用这个

let text = String(format:"Download the app on your iPhone")

// set up activity view controller
let objectsToShare: [AnyObject] = [ text ]
self.activityViewController = UIActivityViewController(
activityItems: objectsToShare, applicationActivities: nil)

self.activityViewController.popoverPresentationController?.sourceView = self.view
// so that iPads won't crash

self.activityViewController.completionWithItemsHandler = { activity, success, items, error in
if success {
// Success handling here
}
}
// exclude some activity types from the list (optional)
self.activityViewController.excludedActivityTypes = [ UIActivityTypeAirDrop, UIActivityTypePostToFacebook ]

// present the view controller
self.presentViewController(self.activityViewController, animated: true, completion: nil)

关于ios - 如何在单击“取消”按钮时关闭 UIActivityViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39637465/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com