Ios 对象之间的通信-C4框架
我正在使用C4的alpha版本,我试图在对象之间发送消息,但我无法让它工作。我试图用一个非常简单的例子,但我不能让它工作。。。我试过这个:Ios 对象之间的通信-C4框架,ios,c4,Ios,C4,我正在使用C4的alpha版本,我试图在对象之间发送消息,但我无法让它工作。我试图用一个非常简单的例子,但我不能让它工作。。。我试过这个: [ashape listenFor:@"touch" from:anothershape andRunMethod:@"receive"]; 但是我没有收到任何消息或者什么都没有 这就是我所拥有的: #import "MyShape.h" @implementation MyShape -(void)receive { C4Log(@"this
[ashape listenFor:@"touch" from:anothershape andRunMethod:@"receive"];
但是我没有收到任何消息或者什么都没有
这就是我所拥有的:
#import "MyShape.h"
@implementation MyShape
-(void)receive {
C4Log(@"this button");
}
@end
我发现你发布的代码有一个主要问题 默认情况下,C4中的所有可见对象在点击时都会发出
触摸开始
通知。在您的代码中,您正在收听的是@“touch”
,而@“touchsbegind”
是您应该收听的内容
改变颜色的方法很容易实现。。。在MyShape.m文件中,可以使用以下方法:
-(void)changeColor {
CGFloat red = RGBToFloat([C4Math randomInt:255]);
CGFloat green = RGBToFloat([C4Math randomInt:255]);
CGFloat blue = RGBToFloat([C4Math randomInt:255]);
self.fillColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
}
为了使事情顺利进行,您的C4WorkSpace.m应该如下所示:
#import "C4WorkSpace.h"
#import "MyShape.h"
@implementation C4WorkSpace {
MyShape *s1, *s2;
}
-(void)setup {
s1 = [MyShape new];
s2 = [MyShape new];
[s1 rect:CGRectMake(100, 100, 100, 100)];
[s2 rect:CGRectMake(300, 100, 100, 100)];
[s1 listenFor:@"touchesBegan" fromObject:s2 andRunMethod:@"changeColor"];
[s2 listenFor:@"touchesBegan" fromObject:s1 andRunMethod:@"changeColor"];
[self.canvas addShape:s1];
[self.canvas addShape:s2];
}
@end
嘿,大卫,在我回答之前有两个问题:(1)“ashape”和“anothershape”都是MyShape这个类的对象吗?(2) 您是否尝试在使用ToucheSBegind方法首次触摸另一个对象时使其中一个对象发生反应?1)是2)是。例如:如果我必须选择正方形,我想在按下第一个正方形时改变第二个正方形的颜色,反之亦然。