2013-10-23 3 views
1

C4 앱의 캔버스에 42 개의 도형을 추가했습니다. 사용자가 어떤 모양을 터치했는지 어떻게 알 수 있습니까? 다음과 같이C4 모양을 클릭 했습니까?

나는 모양을 추가

#import "C4Workspace.h" 

@implementation C4WorkSpace{ 
    C4Shape *greyRect; 
} 

-(void)setup { 
    int imageWidth=53.53; 
    int imageHeight=65.1; 
    for (int i=0; i<42; i++) { 
     int xMultiplier=(i)%6; 
     int yMultiplier= (i)/6; 
     int xPos=xMultiplier*imageWidth; 
     int yPos=yMultiplier*imageHeight; 
     greyRect=[C4Shape rect:CGRectMake(xPos, yPos, imageWidth, imageHeight)]; 
     greyRect.fillColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0]; 
     greyRect.lineWidth=2; 
     greyRect.strokeColor=[UIColor colorWithRed:0.7 green:0 blue:0 alpha:1]; 
     [self listenFor:@"touchesBegan" fromObject:greyRect andRunMethod:@"highlightLetter"]; 

     [self.canvas addShape:greyRect]; 
    } 
} 

-(void)highlightLetter{ 
    C4Log(@"highlightLetter"); 
} 

@end 

나는 거의 유일한 [I]를 클릭 RECT가 가지고있는 번호를 알아야합니다.

하지만 라인을 실행 한 후 그에 액세스하는 방법을 모른다 : [self listenFor:@"touchesBegan" fromObject:greyRect andRunMethod:@"highlightLetter"];

어떤 제안?

답변

1

C4 사이트의 알림 튜토리얼의 WHO SAID WHAT? 부분을 살펴보십시오.

알림 자습서의이 부분에서는 특정 객체의 알림에 반응하여 실제로 알림을 브로드 캐스트하는 객체를 파악하는 방법을 설명합니다.

트릭 알림 받아들이는 방법 구축에 다음 방법을 사용하는 방법 등의 이름으로 :를 포함 가지고변수이 걸리기 때문에 또한

-(void)highlightLetter:(NSNotification *)notification { 
    C4Shape *shape = (C4Shape *)notification.object; 
    //do stuff to the shape 
} 

기억 그래서 :

[self listenFor:@"touchesBegan" 
    fromObject:greyRect 
    andRunMethod:@"highlightLetter:"]; 
+0

이것은 트릭을하고 있습니다. 감사!! – suMi

관련 문제