我正在处理我的应用程序添加twitter功能以共享我当前viewcontroller的屏幕截图。我可以使用构建的方法吗?
答案 0 :(得分:1)
This回答有以下创建屏幕截图的方法:
- (UIImage *)captureView:(UIView *)view {
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
它返回一个UIImage,你可以这样使用它:
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.image = [self captureView:self.view]; // or self.navigationController.view
[self presentViewController:tweetSheet animated:YES completion:^{}];