首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIActivityViewController on iPad

UIActivityViewController on iPad
EN

Stack Overflow用户
提问于 2015-10-01 14:07:10
回答 6查看 15.7K关注 0票数 15

我一直在使用下面的代码来显示UIActivityViewController,当我使用Xcode 6、Swift 1.2和iOS 8时,它工作得很好。然而,当我更新它时,它显示了UIActivityViewController,但是它是完全空白的,没有任何共享选项。你有什么意见建议?

代码语言:javascript
复制
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
        let textToShare = textViewOne.text

            let objectsToShare = [textToShare]
            let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

            let nav = UINavigationController(rootViewController: activityVC)
            nav.modalPresentationStyle = UIModalPresentationStyle.Popover
            let popover = nav.popoverPresentationController as UIPopoverPresentationController!

            popover.sourceView = self.view
            popover.sourceRect = sender.frame

            self.presentViewController(nav, animated: true, completion: nil)

    } else {
        let textToShare = textViewOne.text

        let objectsToShare = [textToShare]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

        self.presentViewController(activityVC, animated: true, completion: nil)

    }
EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2015-10-03 14:27:36

这个已经修好了。

代码语言:javascript
复制
let objectsToShare = [textToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.title = "Share One"
activityVC.excludedActivityTypes = []            
activityVC.popoverPresentationController?.sourceView = self.view
activityVC.popoverPresentationController?.sourceRect = sender.frame
self.presentViewController(activityVC, animated: true, completion: nil)

迅速3.0版:

代码语言:javascript
复制
let objectsToShare = [textToShare]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.title = "Share One"
activityVC.excludedActivityTypes = []
        
activityVC.popoverPresentationController?.sourceView = self.view
activityVC.popoverPresentationController?.sourceRect = sender.frame

self.present(activityVC, animated: true, completion: nil)
票数 18
EN

Stack Overflow用户

发布于 2020-10-14 09:47:34

我与SWIFT 5公司的上述建议斗争,因为:

activity.popoverPresentationController?.sourceRect = sender.frame

在某些情况下不工作,因为发送方在作用域上不可用。相反,尝试使用CGRECT设置,如下所示:

代码语言:javascript
复制
activityController.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY,width: 0,height: 0)

我希望这能帮到一些人。

票数 15
EN

Stack Overflow用户

发布于 2018-10-27 12:45:53

Swift 4.0

代码语言:javascript
复制
    let shareText = "Hi"
    let activity = UIActivityViewController(activityItems: shareText, applicationActivities: nil)
    activity.excludedActivityTypes = []

    if UIDevice.current.userInterfaceIdiom == .pad {
        activity.popoverPresentationController?.sourceView = self.view
        activity.popoverPresentationController?.sourceRect = sender.frame
    }
    self.present(activity, animated: true, completion: nil)
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32889680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档