【问题标题】:Change UIImageView Center - iPhone更改 UIImageView 中心 - iPhone
【发布时间】:2010-06-10 16:09:18
【问题描述】:

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

有人有什么见解吗?

【问题讨论】:

    标签: iphone uiimageview


    【解决方案1】:

    您必须将中心设置为整体:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多