1

Facebook API を使用するアプリケーションに取り組んでいます。このアプリケーションには、2 人の Facebook の友達がいます。最初の友達がデザインを描き、2 番目の友達の Facebook ウォールに投稿します。2 番目の友人はその絵を理解し、最初の友人に返信します。

コードでデザインを作成しましたが、アプリの招待状で友人の壁に投稿する方法がわかりません。

デザインを作成するためのコードは次のとおりです。

- (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 - Sending an image with Sharekit to Facebookを参照してください。

于 2012-05-24T07:04:38.317 に答える