2011-04-05 78 views
4

我一直在爲iPhone做一些編程,現在我冒險進入iPad領域。我想實現的概念依賴於與osx中的時間機器類似的導航。總之,我有許多視圖可以平移和縮放,就像任何普通視圖一樣。然而,視圖使用第三維(在這種情況下是深度)相互堆疊。在這種情況下,用戶將導航到任何視圖,選擇一個字母,於是應用將飛過視圖直到它到達所選字母的視圖。時間機器風格導航

我的問題是:有人可以給出完整的最終代碼如何做到這一點?開玩笑。 :)我需要的是朝着正確的方向前進,因爲我不確定如何開始這樣做,以及是否可以使用可用的框架。任何提示將不勝感激

謝謝!

回答

4

核心動畫 - 或者更具體地說,建立在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); 
    } 
}]; 

而這裏的是什麼樣子,與一對夫婦的隨機顏色的觀點:

Sample screenshot of Time Machine-esque effect

-2

它被稱爲封面流,也可用於iTunes查看藝術作品/相冊。蘋果似乎已經從第三方購買了該技術,並且已經獲得了該專利。但是,如果你谷歌的ios覆蓋流量,你會得到大量的點擊和代碼指向你在正確的方向。

我還沒看,但會認爲它可能是在iOS庫中,但我不知道肯定。

+0

據我所知,封面流只有一邊到另一邊導航,只用兩個維度。因此,這不是我正在尋找的,但無論如何感謝。 – Glitch 2011-04-05 10:04:42

+0

CoverFlow從一側到另一側瀏覽視圖,時間機器從前到後對發現者窗口進行排序,看起來完全不同。 (這有道理嗎?)http://www.macmacken.com/wp-content/files/timemachine_009.png – 2011-04-05 10:05:06

0

你是說右邊這樣的東西? enter image description here

如果是的話,應該是可以的。你將不得不像在圖像上一樣安排視圖,並使它們前後移動。據我所知,這沒有任何框架。