我正在尝试制作一个以编程方式显示图像的代码(最终是多个图像),然后翻译图像。当我尝试翻译此图像时,图像不会移动而是缩小。我已经在另一张我已经粘贴到故事板中的图像上测试了翻译代码,但它确实有效。
这是我的代码:
//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"];
[ZombieView setImage:Zombie];
[self.view addSubview:ZombieView];
//This makes the Person move down until he is behind the railing
[UIView animateWithDuration:9.5
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
CGAffineTransform trans = CGAffineTransformTranslate(self.ZombieView.transform, 0, 640);
ZombieView.transform=trans;
}
completion:nil];
我这是我的头文件:
@property (strong, nonatomic) IBOutlet UIImageView *ZombieView;
@property (strong, nonatomic) IBOutlet UIImage *Zombie;
我确信答案很简单,但我不熟悉IOS中的编码,所以请记住这一点。谢谢!
答案 0 :(得分:1)
我没有看到您的动画代码有任何问题,除了在动画块中您引用通过ZombieView
连接到IBOutlet
的{{1}},而不是您直接声明的那个在动画块之上。
并且,您正在使用通过UIImageView
连接的self.ZombieView
(IBOutlet
)的转换来创建应用于UIImageView
转换的转换( ZombieView
)直接在动画块上方声明。
也许这就是原因。
除此之外,你的动画应该有效。
<强> 附录: 强>
我刚才记得在启用autolayout
时使用转换可能会产生意外结果。因此,在您的情况下,如果在故事板上创建了self.ZombieView
,并且您使用该转换并将其应用于ZombieView
转换,则可以解释您遇到的问题。
所以:在动画块中,将self.ZombieView.transform
更改为ZombieView.transform
,它应该按预期执行。
希望这有帮助。
答案 1 :(得分:-1)
如果您只想翻译此视图,为什么不为该图像设置新框架?
CGRect newFrame = CGRectOffset(ZombieView.frame, 0, 600)
[UIView animateWithDuration:9.5
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
ZombieView.frame = newFrame;
}];