繁体   English   中英

移动一个 uiimageview 动画

[英]Move an uiimageview animated

我怎么能让一个UIImage在20秒内从屏幕底部移动到屏幕顶部(大约每秒35像素)我不是说你应该自己拖动它,但它应该自动移动到顶部. 谢谢

首先, apple doc是你的朋友。 我在这里给你的所有信息都来自于此。 Apple 还提供了大量示例代码,您一定要看一看。

您可以(轻松)完成此操作的方法是使用 UIView 动画。 假设您的图像有一个 UIImageView,您可以使用animateWithDuration:(NSTimeInterval)duration animations:...方法。

例如:

[UIView animateWithDuration:10.0f animations:^{
    //Move the image view to 100, 100 over 10 seconds.
    imageView.frame = CGRectMake(100.0f, 100.0f, imageView.frame.size.width, imageView.frame.size.height);
}];

您可以通过向 animation 添加越来越多的选项、获取完成块等来变得更有趣。这都是通过“animateWithDuration”方法的变体实现的。 那里有大量关于 UIView 动画的教程和大量文档。

如果您不想使用块(上面的 ^{...code...} 位),您可以像这样运行 animation:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:10.0f];
imageView.frame = ...
[UIView commitAnimations];

如果我理解你可以做一个 animation 你自己的 object,在这种情况下试试 beginAnimation

...
initial position

[UIView beginAnimation];
[UIView setAnimationDuration:dim/35.];
[UIView setAnimationCurve:[UIViewAnimationCurveLinear];

your animation

[UIView commitAnimations];
...

用第二名的这个计算 dim/35 计算得到你的 animation 35px/s

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM