更改UIImageView中心-iPhone

更改UIImageView中心-iPhone,iphone,uiimageview,Iphone,Uiimageview,我试着根据iPhone中的加速计值来制作一个小球 此代码不会生成: -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { if(difficulty == @"Easy") { CGFloat newX = (CGFloat)(ball.frame.origin.x + (CGFloat)acceleration.x); CGFloat

我试着根据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种不同的方法,每次都失败了……这只是最近的一次失败


有人有什么见解吗

您必须整体设置中心:

-(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;
}
}