Xcode UIImageView animation jumps back to original position..

690 Views Asked by At

I'm pretty new to xcode. trying to play around a bit, but ran into this strange behavior...

i'm using CoreMotion acceleration to move an image around on the screen.

shortening the moving the UIImageView Movement code...

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

while this is occurring, i have a button, that simply creates another UIImageView on a existing UIView...

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

when this occurs, the movingImage jumps back to the original position it started from. I'm hoping to achieve the addInAnotehrImage to trigger while movingImage is floating around the screen using acceleration of CoreMotion. Anyone can help me identify why the movingImage jumps back to original position when the addInAnotherImage is run?

1

There are 1 best solutions below

0
On

Never mind! i found the issue.

The movingImage was setup with an IBOutlet. had constraints on it.

what i did was change the UIImageView type from

IBOutlet UIImageView *movingImage

to

@property (nonatomic, strong) UIImageView *movingImage;

then synthesized it, and setup beginning coordinate at the ViewDidLoad.