开发者

Time Machine style Navigation

I've been doing some programming for iPhone lately and now I'm venturing into the iPad domain. The concept I want to realise relies on a navigation that is similar to time machine in osx. In short I have a number of views that can be panned and zoomed, as any normal view. However, the views are stacked upon each other using a third dimension (in this case depth). the user will the navigate to any view by, in this case, picking a letter, whereupon the app will fly through the views until it reaches the view of the selected letter.

My question is: can somebody give the complete final code for how to do this? Just kidding. :) What I need is a push in the right direction, since I'开发者_运维技巧m unsure how to even start doing this, and whether it is at all possible using the frameworks available. Any tips are appreciated

Thanks!


Core Animation—or more specifically, the UIView animation model that's built on Core Animation—is your friend. You can make a Time Machine-like interface with your views by positioning them in a vertical line within their parent view (using their center properties), having the ones farther up that line be scaled slightly smaller than the ones below (“in front of”) them (using their transform properties, with the CGAffineTransformMakeScale function), and setting their layers’ z-index (get the layer using the view’s layer property, then set its zPosition) so that the ones farther up the line appear behind the others. Here's some sample code.

// 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);
    }
}];

And here's what it looks like, with a couple of randomly-colored views:

Time Machine style Navigation


do you mean something like this on the right?

Time Machine style Navigation

If yes, it should be possible. You would have to arrange the Views like on the image and animate them going forwards and backwards. As far as I know aren't there any frameworks for this.


It's called Cover Flow and is also used in iTunes to view the artwork/albums. Apple appear to have bought the technology from a third party and also to have patented it. However if you google for ios cover flow you will get plenty of hits and code to point you in the right direction.

I have not looked but would think that it was maybe in the iOS library but i do not know for sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜