2012-05-24 141 views
2

我的工作中,我使用Facebook的API的應用程序。在這個應用程序中有2個Facebook朋友。第一位朋友將繪製設計並將其張貼到第二位朋友的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]; 
} 

我與小矩形的幫助下繪製。我如何發佈他們?

回答

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