核心动画 - 或者更具体地说,建立在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