我試圖執行這段代碼中移動的UIImageView的對象,
我得到在createPosition方法的對象(jumpBall1 ...)編譯器警告:UIImageView may not respont to -setupperLimit, -setlowerLimit, -setspeed
iPhone代碼 - CGPoint分配問題
代碼:
@interface JumpBallClass : UIViewController
{
CGPoint center;
CGPoint speed;
CGPoint lowerLimit;
CGPoint upperLimit;
IBOutlet UIImageView *jumpBall1;
IBOutlet UIImageView *jumpBall2;
}
@property (assign) CGPoint lowerLimit;
@property (assign) CGPoint upperLimit;
@property (assign) CGPoint speed;
@property(nonatomic,retain) IBOutlet UIImageView *jumpBall1;
@property(nonatomic,retain) IBOutlet UIImageView *jumpBall2;
- (void)update;
@end
@implementation JumpBallClass
- (void)update
{
center.x += speed.x;
center.y += speed.y;
if (center.x > upperLimit.x || center.x < lowerLimit.x)
{ speed.x = -speed.x; }
if (center.y > upperLimit.y || center.y < lowerLimit.y)
{ speed.y = -speed.y; }
}
@end
- (void) jumpOnTimer {
NSArray * balls = [NSArray arrayWithObjects:jumpBall1, jumpBall2, nil];
[balls makeObjectsPerformSelector:@selector(update)];
}
- (void) createPosition {
[jumpBall1 setUpperLimit:CGPointMake(60, 211)];
[jumpBall1 setLowerLimit:CGPointMake(0, 82)];
[jumpBall1 setspeed:CGPointMake(2.0,7.0)];
...
}
JumpBallClass是一個UIViewController – 2010-01-04 12:48:49
這並不改變你調用的方法,你已經爲UIImageView上的JumpBallClass定義了一個方法。您需要在JumpBallClass的實例上調用該方法。 – 2010-01-04 13:19:06
所以我需要在不同的類中定義它?在哪裏定義jumpBall對象? – 2010-01-05 13:04:55