I am trying to make a code that programmatically makes an image appear (eventually multiple images), and then translates the image. When I try to translate this image, the image doesn't move and instead shrinks. I have tested the translation code on another image that I pasted into the storyboard already and it worked.
Here is my code:
//this makes a zombie/person
UIImageView *ZombieView =[[UIImageView alloc] initWithFrame: CGRectMake(135 , 0, 50, 75)];
UIImage *Zombie=[UIImage imageNamed:@"free-vector-stick-figure-clip-art_105575_Stick_Figure_clip_art_hight.png"];
//This makes the Person move down until he is behind the railing
CGAffineTransform trans = CGAffineTransformTranslate(self.ZombieView.transform, 0, 640);
@property (strong, nonatomic) IBOutlet UIImageView *ZombieView;
@property (strong, nonatomic) IBOutlet UIImage *Zombie;
I don't see any problem with your animation code, except that within the animation block you are referencing to the
ZombieView that is connected to the one via
IBOutlet, not the one you declare directly above the animation block.
And, you are using the transform of the
self.ZombieView) connected through the
IBOutlet to create a translate that you apply to the transform of the
ZombieView) that is declared directly above the animation block.
Perhaps that is the reason.
Other than that, your animation should work.
I just remembered that using transforms when
autolayout is enabled could produce unexpected results. So, in your case, if
self.ZombieView is created on storyboard with that turned on and with you using that transform and apply it to the
ZombieView transform, what you are experiencing can be explained.
So: within the animation block, change
ZombieView.transform and it should do as you expect.
Hope this helps.