【问题标题】:Xcode UIImageView animation jumps back to original position..Xcode UIImageView 动画跳回原来的位置..
【发布时间】:2014-11-17 01:32:48
【问题描述】:

我对 xcode 还是很陌生。想玩一会儿,却遇到了这种奇怪的行为……

我正在使用 CoreMotion 加速在屏幕上移动图像。

缩短移动 UIImageView 的移动代码...

        dispatch_async(dispatch_get_main_queue(), ^{

        CGRect recta = movingImage.frame;

        //data is the coremotion info.
        float dataAccelerationX = data.acceleration.x;
        float dataAccelerationY = -data.acceleration.y;

        float movetoX = recta.origin.x + (dataAccelerationX * stepMoveFactor);
        float maxX = self.view.frame.size.width - recta.size.width;

        float movetoY = (recta.origin.y + recta.size.height) - (dataAccelerationY * stepMoveFactor);
        float maxY = self.view.frame.size.height;

        movingImage.frame = recta;
    });

发生这种情况时,我有一个按钮,它只是在现有 UIView 上创建另一个 UIImageView...

-(void)addInAnotherImage
{
    dispatch_async(dispatch_get_main_queue(), ^{
    NSLog(@"making UIImageView with image file");
    UIImageView *someImage =[[UIImageView alloc] initWithFrame:CGRectMake(200,200,200,200)];
    someImage.image=[UIImage imageNamed:@"someimage.png"];
    [self.view addSubview:someImage];
    });
}

当这种情况发生时,movingImage 会跳回到它开始的原始位置。我希望实现 addInAnotehrImage 在使用 CoreMotion 加速在屏幕上浮动时触发 addInAnotehrImage。任何人都可以帮助我确定为什么在运行 addInAnotherImage 时,movingImage 会跳回原始位置?

【问题讨论】:

    标签: ios objective-c xcode uiimageview core-motion


    【解决方案1】:

    没关系!我发现了问题。

    movingImage 是使用 IBOutlet 设置的。有限制。

    我所做的是将 UIImageView 类型从

    IBOutlet UIImageView *movingImage
    

    @property (nonatomic, strong) UIImageView *movingImage;
    

    然后合成它,并在 ViewDidLoad 处设置起始坐标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多