2010-06-10 69 views
0

我正在尝试制作一个基于iPhone中的加速计值进行滚动的小球。更改UIImageView中心 - iPhone

此代码不会建:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration 
{ 
if(difficulty == @"Easy") 
{ 
    CGFloat newX = (CGFloat)(ball.frame.origin.x + (CGFloat)acceleration.x); 
    CGFloat newY = (CGFloat)(ball.frame.origin.y + (CGFloat)acceleration.y); 
    ball.frame.origin.x = newX; 
    ball.frame.origin.y = newY; 
} 
} 

它给了我所需要的分配错误的左操作数是左值。

我试过100种不同的东西,每次都失败......这只是最新的失败。

任何人有任何见解?

回答

2

你必须设置中心,在它的全部:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration 
{ 
if(difficulty == @"easy") 
{ 
    CFPoint center = ball.center; 
    CGFloat center.x = (CGFloat)(ball.x + (CGFloat)acceleration.x); 
    CGFloat center.y = (CGFloat)(ball.y + (CGFloat)acceleration.y); 
    ball.center = center; 
} 
}