簡體   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