英文:
Dismiss Activity View Controller above view
问题
I can provide a translation of your request:
如何通过点击视图上方来关闭 UIActivityViewController。
我试图在上方的 UIActivityViewController 上方的红色框区域被点击时复制 self.dismiss 的行为(如图所示)。
Please note that the code portion is not translated, as requested.
英文:
How can I dismiss an UIActivityViewController by tapping above the view.
// Setting url
let secondActivityItem : NSURL = NSURL(string: url)!
let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [secondActivityItem], applicationActivities: nil)
if(UIDevice.current.userInterfaceIdiom == .pad){
// This lines is for the popover you need to show in iPad
activityViewController.isModalInPresentation = false
activityViewController.popoverPresentationController?.sourceView = self.view//(self as! UIButton)
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
}else{
// This lines is for the popover you need to show in iPad
activityViewController.isModalInPresentation = true
activityViewController.popoverPresentationController?.sourceView = (self as! UIButton)
// This line remove the arrow of the popover to show in iPad
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.down
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
}
// Pre-configuring activity items
activityViewController.activityItemsConfiguration = [
UIActivity.ActivityType.message
] as? UIActivityItemsConfigurationReading
// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivity.ActivityType.postToWeibo,
UIActivity.ActivityType.print,
UIActivity.ActivityType.assignToContact,
UIActivity.ActivityType.saveToCameraRoll,
UIActivity.ActivityType.addToReadingList,
UIActivity.ActivityType.postToFlickr,
UIActivity.ActivityType.postToVimeo,
UIActivity.ActivityType.postToTencentWeibo,
UIActivity.ActivityType.postToFacebook,
UIActivity.ActivityType.postToTwitter
]
self.present(activityViewController, animated: true, completion: nil)
I am trying to replicate self.dismiss when the red box area is tapped above the UIActivityViewController (as shown in the image)
答案1
得分: 0
设置 isModalInPresentation
为 true
后,控制器移除了对于超出区域的轻点手势的支持。
解决方案:不要将 isModalInPresentation
设置为 true
。
英文:
After setting isModalInPresentation to true, controller removes support for out-of-area tap gestures.
Solution: don't set isModalInPresentation to true.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论