3

我有一個UIImageView我試圖動畫一肯伯恩斯般的平移/縮放操作。我想開始以臉部爲中心(具體來說,就是說,人的鼻子的末端)並縮小至圖像的整個大小。該代碼是這樣的:的iOS:肯伯恩斯動畫的實現需要意想不到的參數

image.frame = // some frame that zooms in on the image; 
image.center = // tip of the nose 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:3]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

image.frame = // original frame 
image.center = // original centerpoint 

[UIView commitAnimations]; 

在Photoshop中對鼻子的座標的頂端是完全從我不得不衝壓成上面的代碼時的動畫效果實際上集中在鼻子上的圖像的值不同開始。我試圖反映軸,乘以一個因素的規模......我似乎無法弄清楚爲什麼iOS的數字是顯着的v。我從Photoshop中推導出來的。

有人能說出兩個座標系之間的差異?

一些額外的信息:

  • image是一個UIImageView,是一個UIViewController
  • 說的UIViewController的直接子水平定向 - 整個應用程序在橫向模式下運行。
+0

有對Ken Burns效果爲iOS這裏像樣的圖書館:https://github.com/jberlana/iOSKenBurns 雖然它可以使用一個小的工作。 – shim 2013-07-14 15:10:08

回答

3

設置幀和中心是有點冗餘。該框架應該足夠了,使用這兩個你失去了一部分的設置。

編輯:更準確地說,你應該只有兩個幀的設置,讓CoreAnimation做休息。

2

問題是動畫是以某種複雜的方式發生的。無論到底如何,但結果如何。您無法設置初始參數並使用一種方法對它們進行動畫處理。您必須設置初始參數,然後發送動畫將發生的所有[UIView *動畫]消息[self performSelector:withObject:afterDelay:]消息。

所以你的代碼看起來像這樣。

- (void)one { 
    image.frame = // some frame that zooms in on the image; 
    image.center = // tip of the nose 

    [self performSelector:@selector(two) withObject:nil afterDelay:0]; 
} 

- (void)two { 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:3]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

    image.frame = // original frame 
    image.center = // original centerpoint 

    [UIView commitAnimations]; 
} 
相關問題