2011-04-05 81 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

如果是的话,应该是可以的。你将不得不像在图像上一样安排视图,并使它们前后移动。据我所知,这没有任何框架。