如何在社交媒体中显示 UIView post
how to display a UIView in a social media post
我什至不知道这是否可行,但我想知道是否可以将 UIView 及其所有内容插入推文或 facebook post 所以当用户发送推文时在应用程序中,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.")
}
}
}
您可以将视图捕获到 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
}
我什至不知道这是否可行,但我想知道是否可以将 UIView 及其所有内容插入推文或 facebook post 所以当用户发送推文时在应用程序中,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.")
}
}
}
您可以将视图捕获到 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
}