ios - 如何在社交媒体帖子中显示 UIView

标签 ios facebook swift twitter uiview

我什至不知道这是否可行,但我想知道是否可以将 UIView 及其所有内容插入到推文或 Facebook 帖子中,这样当用户从应用程序发送推文时,图像推文中显示了 UIView。任何帮助表示赞赏。这是我的尝试,上面写着//THIS LINE DOES NOT DO ANYTHING:

func sendSocialPost(serviceType:String) {

    if SLComposeViewController.isAvailableForServiceType(serviceType) {

        // Users device is good for Twitter
        let socialDialog:SLComposeViewController = SLComposeViewController(forServiceType: serviceType)

        socialDialog.setInitialText("Whats the mood like?")

        // THIS LINE DOES NOT DO ANYTHING
        socialDialog.inputAccessoryView?.insertSubview(self.scrollViewView, aboveSubview: self.contentView)

        socialDialog.completionHandler = { (result:SLComposeViewControllerResult) in

            // Check if the user sent the tweet of cancelled it
            if result == SLComposeViewControllerResult.Done {
                // User has sent social post
                NSLog("post sent")
            }
            else if result == SLComposeViewControllerResult.Cancelled {
                NSLog("post cancelled")
            }
        }

        // Present the social dialog box
        self.presentViewController(socialDialog, animated: true, completion: nil)

    }
    else {

        // Social Account credentials haven't been added to the settings
        if serviceType == SLServiceTypeTwitter {
            NSLog("A Twitter account needs to be set up in the Settings app.")
        }
        else if serviceType == SLServiceTypeFacebook {
            NSLog("A Facebook account needs to be set up in the Settings app.")
        }

    }

}

最佳答案

您可以将 View 捕获到 UIImage 并发推文...... 如果那是你的意思..

    func captureViewArea() -> UIImage {
        UIGraphicsBeginImageContextWithOptions(self.viewToCapture.bounds.size, self.viewToCapture.opaque, 0.0)
        self.viewToCapture.layer.renderInContext(UIGraphicsGetCurrentContext())
        let viewImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return viewImage
    }

关于ios - 如何在社交媒体帖子中显示 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30633459/

相关文章:

swift - Swift 类扩展的文档注释

iphone - iOS:接到电话时显示提醒?

ios - IBOutlets在iOS9下应该强还是弱?

iphone - AssetsLibrary 框架的内存管理问题

objective-c - 使用 FBDialog 上传 UIImage

Facebook 图形 API : Get Events by Venue

ios - 如何将 Codable 协议(protocol)与引用类型一起使用?

c# - 如何使用 .net 连接到 Facebook 聊天?

ios - NSSet 过滤的对象从先前从核心数据中获取的对象中删除

ios - 存储不同 NSData 时 Realm 文件大小差异过大