tags:

views:

3255

answers:

3

I am facing problems in flipping views in iPhone.

I have two views in appDelegate. I want to flip them once user clicks on a button.

I have the following code:

CATransition *transition = [CATransition animation];

transition.duration = 0.75;
[transition @"twist"];
[transition setSubtype:@"fromRight"];

transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[transition setFillMode:@"extended"];

[[window layer] addAnimation:transition forKey:nil];


[window addSubview:self.s.view];
[CATransaction commit];

But this is not working. Do anybody knows a better way to flip the views on window side.

What I am doing is calling the method from appDelegate in the respective viewControllers to flip the views.

+2  A: 

See The Elements sample code. Particularly AtomicElementViewController -flipCurrentView.

Rob Napier
Only Instead of content view you need to add window as follows:[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];if You dont want to use content view and do it on window side.
rkb
I'm curious why you would do it with the window itself? That's a very unusual approach; generally you use the contentView of the window and leave the window alone.
Rob Napier
+6  A: 

If you're using the 3.0 SDK and all you want is a simple flip transition (ala the Weather app) then you don't need to go down to CATransition. The higher-level UIView animation transitions will do what you want but with 3.0 there is an even easier way: simply present your new view as a modal view controller and set the modal transition style to flip. From within the first controller:

UIViewController *controllerForSecondView = ..;
controllerForSecondView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controllerForSecondView animated:YES];

Flip back again by using dismissModalViewController.

Documentation Reference

Luke Redpath
Thanks for the great tip!NB to anyone reading: as per Jared's answer, the setting should be set on 'controllerForSecondView', not 'self'.
William Denniss
Quite right, I should have edited this ages ago when Jared first posted his answer. I've now corrected this.
Luke Redpath
+4  A: 

@Luke - thanks, this sample helped me...1 correction though (based on UIViewController.h)

UIViewController *controllerForSecondView = ..;
controllerForSecondView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controllerForSecondView animated:YES];

From the header file comments:

// Defines the transition style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter. // Defaults to UIModalTransitionStyleSlideVertical. @property(nonatomic,assign) UIModalTransitionStyle modalTransitionStyle

Jared
Well spotted! I must have missed that, but thats what you get when you don't actually run the code you are writing ;)
Luke Redpath