I have an app in progress that has a lot of views for various purposes. Within one of them, I'd like to use an existing View as the 'background', and then have a view inserted within that flips - very similar to the "Now Playing" view on an iPhone/iPod where the album cover flips between the image and the track listings. Can someone point me in the right direction?
-
Why did I get voted down for asking this question? – wayneh Mar 21 '12 at 15:43
-
Would you please give feedback, if my answer was helpful? – dom Mar 23 '12 at 08:24
1 Answers
Take a look at Apples View Controller Programming Guide for iOS. I guess the easiest way would be using a modal view with UIModalTransitionStyleFlipHorizontal
set as transition style (look for "Presenting a View Controller and Choosing a Transition Style" on the guide I posted.).
Tutorials:
- http://timneill.net/2010/09/modal-view-controller-example-part-1/
- http://timneill.net/2010/11/modal-view-controller-example-part-2/
EDIT
I guess you're using a UINavigationController
, so here's an example ViewController, which keeps the navigation bar visible. Just put a second view inside your view controller and hide it. Than implement a method (I used an IBAction, which I hook to a button using InterfaceBuilder), which switches between these views:
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

- 11,894
- 10
- 51
- 74
-
Thanks for the link, but I think I'll need something more, like a tutorial if you know of one. – wayneh Mar 23 '12 at 15:07
-
@wayneh I added links. Work through them and you should be able to implement a modal view on your own :) – dom Mar 23 '12 at 15:27
-
I think I need to take it to another question at this point. You've been helpful and I've read a lot of other threads and tutorials. I've gotten the view to flip and the NavBar remains static, but the Toolbar flips and I have to make it static too. Thanks again. – wayneh Mar 26 '12 at 22:56
-
That's very similar to the code I ended up using, but I still have the Toolbar flipping with the view. I'm going to check this answer since you've been so helpful. Here's the new question which specifically deals with the Toolbar (if you're interested) http://stackoverflow.com/questions/9881128/how-to-make-toolbar-static-when-flipping-views – wayneh Mar 27 '12 at 14:02
-
1Found the last piece http://stackoverflow.com/questions/4687770/is-there-a-way-to-use-uiviewanimationoptiontransitioncurlup-without-it-animating and deleted the above mentioned question 9881128 since all the info is now within this thread. – wayneh Mar 27 '12 at 20:49