簡體   English   中英

如何創建多個UIImageView動畫,使用CFAffineTransform在上一個動畫結束后開始一個動畫

[英]How to create multiple UIImageView animations, starting one animation after previous animation ends using CFAffineTransform

首先,感謝您閱讀我的問題。 我目前正在嘗試使用CFAffineTransform執行多個動畫來復制kens燃燒效果。

嘗試實現:縮放至圖像,然后向右平移圖像。

問題:一旦開始第二動畫,我的圖像將相對於原始圖像進行平移,而不是相對於第一圖像的最終產品進行平移。 這不是我想要達到的效果。

第一個動畫是放大圖像。

[UIView beginAnimations:@"zoomin" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:5];

CGAffineTransform zoomIn = CGAffineTransformMakeScale(5.8, 5.8);

imageView.transform = zoomIn;

[UIView commitAnimations];

第二個動畫是將圖像平移到左側。

[UIView beginAnimations:@"panning" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:5];

CGAffineTransform moveRight = CGAffineTransformMakeTranslation(200, 0);

imageView.transform = moveRight;

[UIView commitAnimations];

僅在第一個動畫結束后才調用第二個動畫代碼。

它不起作用,因為您正在使用CGAffineTransformMakeTranslation,這意味着它應該從原始位置開始(仿射是身份矩陣,並將視圖置於未轉換狀態),您應該使用CGAffineTransformTranslate,它采用所需的(或當前變換)矩陣作為第一個參數。

因此,如果您這樣做:

CGAffineTransform moveRight = CGAffineTransformTranslate(imageView.transform ,200, 0);

你用過

CGAffineTransform moveRight = CGAffineTransformMakeTranslation(200, 0);

與以下內容相同:

CGAffineTransform moveRight = CGAffineTransformTranslate(CGAffineTransformIdentity ,200, 0);

我建議您閱讀一篇很棒的文章Demystifying CGAffineTransform

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM