核心動畫 - 或者更具體地說,建立在Core Animation上的UIView動畫模型 - 就是你的朋友。你可以通過將它們放置在其父視圖中的垂直線上(使用它們的center
屬性)來製作一個類似於Time Machine的界面,將該視線的上方的那些縮放比下面的縮小(「在前面「)它們(使用transform
屬性和CGAffineTransformMakeScale
函數),並設置其圖層的z-index(使用視圖的layer
屬性獲取圖層,然後設置它的zPosition
),以便遠離其他圖層的圖層出現在其他圖層的後面。以下是一些示例代碼。
// animate an array of views into a stack at an offset position (0 has the first view in the stack at the front; higher values move "into" the stack)
// took the shortcut here of not setting the views' layers' z-indices; this will work if the backmost views are added first, but otherwise you'll need to set the zPosition values before doing this
int offset = 0;
[UIView animateWithDuration:0.3 animations:^{
CGFloat maxScale = 0.8; // frontmost visible view will be at 80% scale
CGFloat minScale = 0.2; // farthest-back view will be at 40% scale
CGFloat centerX = 160; // horizontal center
CGFloat frontCenterY = 280; // vertical center of frontmost visible view
CGFloat backCenterY = 80; // vertical center of farthest-back view
for(int i = 0; i < [viewStack count]; i++)
{
float distance = (float)(i - offset)/[viewStack count];
UIView *v = [viewStack objectAtIndex:i];
v.transform = CGAffineTransformMakeScale(maxScale + (minScale - maxScale) * distance, maxScale + (minScale - maxScale) * distance);
v.alpha = (i - offset > 0) ? (1 - distance) : 0; // views that have disappeared behind the screen get no opacity; views still visible fade as their distance increases
v.center = CGPointMake(centerX, frontCenterY + (backCenterY - frontCenterY) * distance);
}
}];
而這裏的是什麼樣子,與一對夫婦的隨機顏色的觀點:
據我所知,封面流只有一邊到另一邊導航,只用兩個維度。因此,這不是我正在尋找的,但無論如何感謝。 – Glitch 2011-04-05 10:04:42
CoverFlow從一側到另一側瀏覽視圖,時間機器從前到後對發現者窗口進行排序,看起來完全不同。 (這有道理嗎?)http://www.macmacken.com/wp-content/files/timemachine_009.png – 2011-04-05 10:05:06