Q:

UIimage will not move on btn press, what am i doing wrong?

I am trying to move a UIImage, first button press creates the image and second press moves it.
The image only needs to exist upon pressing the button.
In the simulator it creates the button and places it, the second time it click just doesn't do anything.
This is my Code
- (IBAction) btn:(id)sender {

    UIImageView *myImage = [[UIImageView alloc] init];

    myImage.image = [UIImage imageNamed:@"keyframe"];

    if (startUp == 1){

        //Create Image and add to view
        myImage.frame = CGRectMake(200, 300, 10, 10);
        myImage.image = [UIImage imageNamed:@"keyframe"];
        [self.view addSubview:myImage];

        //Set startUp to 0 and output rect value
        startUp = 0;
        NSLog(@"currentFrame %@", NSStringFromCGRect(myImage.frame));

    }else if (startUp == 0){

        //Change position, size and log to debug
        myImage.frame = CGRectMake(500,100 ,20, 20);
        NSLog(@"newFrame %@", NSStringFromCGRect(myImage.frame));
    }
}

How do you programmatically move a programmatically added UIimage?
I tried changing the center value but that doesn't work either.

A:

Try something like this – tested and working sample:
#import "ViewController.h"

@interface ViewController () {
    BOOL startUp;

    UIImageView *myImage;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    startUp = YES;
}

- (IBAction)doWork:(id)sender {
    if (startUp) {
        UIImage *img = [UIImage imageNamed: @"keyframe"];
        myImage = [[UIImageView alloc] initWithImage: img];

        [myImage sizeToFit];

        [myImage setCenter: CGPointMake(200, 300)];

        [self.view addSubview: myImage];

        startUp = NO;
    } else {
        [myImage setCenter: CGPointMake(400, 500)];
    }
}

@end

