我有一種感覺,我忽略了一些基本的東西,但是找到它比在互聯網上錯誤的更好的方法是什麼?CAGradientLayer屬性不在UIView動畫塊內動畫
我有一個相當基本的用戶界面。我的UIViewController
的視圖是+layerClass
爲CAGradientLayer
的子類。根據用戶的操作,我需要移動一些UI元素,並更改背景漸變的值。該代碼看起來是這樣的:
[UIView animateWithDuration:0.3 animations:^{
self.subview1.frame = CGRectMake(...);
self.subview2.frame = CGRectMake(...);
self.subview2.alpha = 0;
NSArray* newColors = [NSArray arrayWithObjects:
(id)firstColor.CGColor,
(id)secondColor.CGColor,
nil];
[(CAGradientLayer *)self.layer setColors:newColors];
}];
的問題是,我在這塊子視圖改變動畫就好了(東西移動和淡入淡出),但改變漸變的顏色沒有。它只是互換。
現在,the documentation does say動畫塊中的Core Animation代碼不會繼承塊的屬性(持續時間,緩動等)。但是,這種情況是不是完全定義了動畫交易? (文檔的含義似乎是,你會得到一個默認的動畫,我沒有得到。)
我是否有使用明確的CAAnimation
使這項工作? (如果是這樣,爲什麼?)
神奇的發現!從來沒有猜到這一點。 – 2012-08-31 04:07:13