关闭上面的活动视图控制器

huangapple go评论62阅读模式
英文:

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

设置 isModalInPresentationtrue 后,控制器移除了对于超出区域的轻点手势的支持。

解决方案:不要将 isModalInPresentation 设置为 true

英文:

After setting isModalInPresentation to true, controller removes support for out-of-area tap gestures.

Solution: don't set isModalInPresentation to true.

huangapple
  • 本文由 发表于 2023年2月10日 11:16:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定