加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 集成iOS6 facebook功能

发布时间:2020-12-14 17:39:17 所属栏目:百科 来源:网络整理
导读:我正在尝试使用iOS6 Facebook功能将我的应用程序的屏幕截图导出到Facebook.按下按钮时,如何在应用程序内部显示选项? 以下是我目前的代码.我想截取屏幕截图,同时使用iOS6 Facebook功能导出到Facebook. - (IBAction)export1:(id)sender{NSIndexPath *indexPat
我正在尝试使用iOS6 Facebook功能将我的应用程序的屏幕截图导出到Facebook.按下按钮时,如何在应用程序内部显示选项?

以下是我目前的代码.我想截取屏幕截图,同时使用iOS6 Facebook功能导出到Facebook.

- (IBAction)export1:(id)sender{

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath
                      atScrollPosition:UITableViewScrollPositionTop
                              animated:YES];
exporting.hidden=YES;

CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
    UIGraphicsBeginImageContextWithOptions(imageSize,NO,0);

else
    UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();

// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
    {
        // -renderInContext: renders in the coordinate space of the layer,// so we must first apply the layer's geometry to the graphics context
        CGContextSaveGState(context);
        // Center the context around the window's anchor point
        CGContextTranslateCTM(context,[window center].x,[window center].y);
        // Apply the window's transform about the anchor point
        CGContextConcatCTM(context,[window transform]);
        // Offset by the portion of the bounds left of and above the anchor point
        CGContextTranslateCTM(context,-[window bounds].size.width * [[window layer] anchorPoint].x,-[window bounds].size.height * [[window layer] anchorPoint].y);

        // Render the layer hierarchy to the current context
        [[window layer] renderInContext:context];

        // Restore the context
        CGContextRestoreGState(context);
    }
}

// Retrieve the screenshot image
CGRect contentRectToCrop = CGRectMake(0,70,740,740);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage],contentRectToCrop);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(croppedImage,nil,nil);

解决方法

Here是如何使用iOS6中内置的Facebook SDK轻松地将图像发布到Facebook.如果这对您有任何帮助,请感到高兴.快乐编码:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读