翻转视图就像现在在iTunes中播放?

时间:2012-03-20 21:39:23

标签: iphone objective-c xcode

我有一个正在进行的应用程序,它有很多用于各种目的的视图。在其中一个中,我想使用现有的视图作为“背景”,然后在翻转中插入视图 - 非常类似于iPhone / iPod上的“正在播放”视图,其中专辑封面翻转图像和曲目列表。 有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:4)

看看苹果View Controller Programming Guide for iOS。我想最简单的方法是使用将UIModalTransitionStyleFlipHorizontal设置为过渡样式的模态视图(在我发布的指南中查找“呈现视图控制器并选择过渡样式”。)。

教程:
- http://timneill.net/2010/09/modal-view-controller-example-part-1/
- http://timneill.net/2010/11/modal-view-controller-example-part-2/

修改

我猜你正在使用UINavigationController,所以这里是一个示例ViewController,它可以使导航栏保持可见。只需在视图控制器中放置第二个视图并隐藏它。比实现一个方法(我使用IBAction,我使用InterfaceBuilder挂钩到一个按钮),它在这些视图之间切换:

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    UIView *backSideView;
}

- (IBAction)switchViews:(id)sender;

@end

ViewController.h:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    backSideView = [[UIView alloc] initWithFrame:[self view].bounds];
    [backSideView setBackgroundColor:[UIColor greenColor]];

    // ... put stuff you want inside backSideView ...

    [backSideView setHidden:YES];
    [[self view] addSubview:backSideView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)switchViews:(id)sender
{
    if ( [backSideView isHidden] )
    {
        [UIView transitionWithView:self.view 
                          duration:1.0 
                           options:UIViewAnimationOptionTransitionFlipFromLeft
                        animations:^{ [backSideView setHidden:NO]; } 
                        completion:^(BOOL finished){ [self setTitle:@"BackView"]; }
         ];
    }
    else
    {
        [UIView transitionWithView:self.view 
                          duration:1.0 
                           options:UIViewAnimationOptionTransitionFlipFromRight
                        animations:^{ [backSideView setHidden:YES]; } 
                        completion:^(BOOL finished){ [self setTitle:@"FrontView"]; }
         ];
    }
}

@end