1

我正在开发一个使用 Facebook API 的应用程序。在这个应用程序中有 2 个 Facebook 朋友。第一个朋友将绘制一个设计并将其发布在第二个朋友的 Facebook 墙上。然后第二个朋友将理解该绘图并回复第一个朋友。

在我的代码中,我做了一个设计,但我不知道如何通过我的应用邀请将其发布到朋友的墙上。

这是进行设计的代码:

- (void)drawRect:(CGRect)rect
{
    prelocation=lastLocation;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touchOb=[touches anyObject];

    prelocation=[touchOb locationInView:self];

    //Get value of selected button

    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];

    NSString *value= [defaults objectForKey:@"clickValue"];

    NSLog(@" value of flag is %@",value);


    if([value isEqualToString:@"yes"])
    {
        NSLog(@" in Erasing");

        CGRect rect1=CGRectMake(prelocation.x,prelocation.y,4,4);

        UIView *view1=[[UIView alloc] initWithFrame:rect1];

        view1.backgroundColor=[UIColor whiteColor];

        [self addSubview:view1]; 
    }
    else
    {   
        if(inkIndicator.value>0.0)
        {
            NSLog(@" in drawing");

            CGRect rect1=CGRectMake(prelocation.x,prelocation.y,2,2);

            UIView *view1=[[UIView alloc] initWithFrame:rect1];

            view1.backgroundColor=[UIColor blueColor];

            [self addSubview:view1];

            counter++;

        } 
        if(counter==10)
        {
            inkIndicator.value--;
            counter=0;
        }
    }

    [self setNeedsDisplay];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touchOb=[touches anyObject];

    lastLocation=[touchOb locationInView:self];

    //    NSLog(@"in start slidr value is %f",drawController.inkIndicator.alpha);

    //Get value of selected button


    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];

    NSString *value= [defaults objectForKey:@"clickValue"];

    NSLog(@" value of flag is %@",value);


    if([value isEqualToString:@"yes"])
    {
        NSLog(@" in Erasing");

        CGRect rect1=CGRectMake(prelocation.x,prelocation.y,4,4);

        UIView *view1=[[UIView alloc] initWithFrame:rect1];

        view1.backgroundColor=[UIColor whiteColor];

        [self addSubview:view1]; 
    }
    else
    {
        if(inkIndicator.value>0.0)
        {
            NSLog(@" in drawing");

            CGRect rect1=CGRectMake(prelocation.x,prelocation.y,2,2);

            UIView *view1=[[UIView alloc] initWithFrame:rect1];

            view1.backgroundColor=[UIColor blueColor];

            [self addSubview:view1];

            counter++;

            NSLog(@" slidr value is %f",inkIndicator.value);
        }

        if(counter==10)
        {
            inkIndicator.value--;
            counter=0;
        }

    }

    [self setNeedsDisplay];
}

我是在小矩形的帮助下绘制的。我怎样才能发布它们?

4

1 回答 1

0

您将不得不创建一个 UIImage 最简单的方法是将 UIView 捕获到 UIImage 中,请使用以下代码

-(UIImage*)captureScreen:(UIView*) viewToCapture
{
    //UIGraphicsBeginImageContext(viewToCapture.bounds.size);
    UIGraphicsBeginImageContextWithOptions(viewToCapture.bounds.size, viewToCapture.opaque, 0.0);
    [viewToCapture.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return viewImage;
}

然后在创建 UIImage 后,您需要将其发送到 facebook,请参阅此问题iPhone 的答案 - 使用 Sharekit 将图像发送到 Facebook

于 2012-05-24T07:04:38.317 回答