Push ViewController with modal animation (horizontal flip) - iphone

I need to push a view controller to another view controller.
menuVC -> VC1 ->VC2
going from menuVC to VC1 requires no animation, but going from VC1 to VC2 and from VC2 to VC1 requires the flip animaton to occur.
However, when going from VC2 to menuVC, no animation is needed.
I am using the following code:
(from how to push a viewController with flip animation)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
FlashCardVC *flashCardVC = [[FlashCardVC alloc] init];
[self.navigationController pushViewController:flashCardVC animated:NO];
[UIView commitAnimations];
The screen goes completely blank when I try and do the above.
What is wrong?

You really should be using block based animations now. Also, if you're instantiating a storyboard controller from a controller that's also in the same storyboard, you can more easily access that storyboard with self.storyboard.
-(IBAction)flipToNext:(id)sender {
SecondController *next = [self.storyboard instantiateViewControllerWithIdentifier:#"Next"];
[self.navigationController pushViewController:next animated:NO];
[UIView transitionWithView:self.navigationController.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];
}

Use these Extension in Swift 4.2
For push and pop view controller with horizontal flip Animation
extension UINavigationController {
func pushViewControllerWithFlipAnimation(viewController:UIViewController){
self.pushViewController(viewController
, animated: false)
if let transitionView = self.view{
UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromLeft, animations: nil, completion: nil)
}
}
func popViewControllerWithFlipAnimation(){
self.popViewController(animated: false)
if let transitionView = self.view{
UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromRight, animations: nil, completion: nil)
}
}
}

Great Answer:
Showing pushviewcontroller animation look like presentModalViewController
(code)
//UIViewController *yourViewController = [[UIViewController alloc]init];</s>
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: yourViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
However, this produced a blank screen also.
Instead, if you are using storyboards, it's best to instantiate through the storyboard:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle bundleForClass:[self class]]];
YourViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:#"yourViewControllerID"];
yourViewControllerID is set in storyboard under identity inspector for the yourviewcontroller class.

Related

How to retain superview when adding a subview to it in iphone?

I had an application in which i am having a view controller which is an appdelegate instance.I am adding that view to the self.navigationcontrollers view in order to place it above navigation bar.lke this `
if(appDelegate.viewcontroller==nil)
{
appDelegate.viewcontroller = [[ViewController alloc] init];
[self.navigationController.view addSubview:appDelegate.viewcontroller.view];
NSLog(#"My view frame: %#", NSStringFromCGRect(appDelegate.viewcontroller.view.frame));
appDelegate.viewcontroller.view.tag=7;
appDelegate.viewcontroller.view.frame =CGRectMake(0,480,300,460);
[UIView animateWithDuration:.50
animations:^{
appDelegate.viewcontroller.view.frame =CGRectMake(0,30,300,440);
}];
[appDelegate.viewcontroller viewWillAppear:YES];
}
else
{
NSLog(#"My view frame: %#", NSStringFromCGRect(appDelegate.viewcontroller.view.frame));
appDelegate.viewcontroller.view.frame=CGRectMake(0, 30,300, 440);
[self.navigationController.view addSubview:appDelegate.viewcontroller.view];
appDelegate.viewcontroller.view.frame =CGRectMake(0,480,300,460);
[UIView animateWithDuration:.50
animations:^{
appDelegate.viewcontroller.view.frame =CGRectMake(0,30,300,440);
}];
[appDelegate.viewcontroller viewWillAppear:YES];
}
...Now i am adding another viewcontrollers view in to this view by
contactphoneForAddfriend= [[EventsViewController alloc]initWithNibName:#"EventsViewController" bundle:nil];
contactphoneForAddfriend.orgarray=self.eventsArray;
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.view cache:NO];
[self.view addSubview:contactphoneForAddfriend.view];
[UIView commitAnimations];
` and then from that view controller when i am going in to the background of the application ...that appdelegate viewcontroller is showing as nil.How come this happen.after all its an appdelegate variouble.when i remove he added view and then go background it is there.Can anybody point me in where i am going wrong?
Checked you code.And found viewController is not nil.Check yourself by applying some code in this method
- (void)applicationDidEnterBackground:(UIApplication *)application
{
if (self.viewController==nil) {
NSLog(#"ViewController is nil");
}else{
NSLog(#"ViewController Has value %#",NSStringFromClass([self.viewController class]));
}
}

UITabController flip

I have TabBarController in my AppDelegate :
IBOutlet TabBarViewController *tab;
This is the main controller in my app.
and in one of the viewcontroller inside the tabs i want to add a UIButton that when the user press it all the tabcontroller will change to another uiviewcontroller with flip animation.
i tried to achive it with this method:
RadioMainVC *radioMainVC = [[RadioMainVC alloc] initWithNibName:#"RadioMainVC" bundle:nil];
UINavigationController *radioNav = [[UINavigationController alloc] initWithRootViewController:radioMainVC];
[UIView beginAnimations:#"animation" context:nil];
[self.tabBarController presentModalViewController:radioNav animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.tabBarController.view cache:NO];
[UIView commitAnimations];
And the flip won't work,any idea how to fix it?
Unfortunately I haven't tested this code but it might do the trick:
[UIView transitionFromView: self.tabBarController.view
toView: radioNav.view
duration: 0.5
options: UIViewAnimationTransitionFlipFromLeft
completion: ^(BOOL finished) {
window.rootViewController = radioNav;
}];

Custom Transition Between Navigation Controllers

I want to have a custom transition between two navigation controllers. Let's call the first one sourceController and the other one detailNavController.
Here's my code:
NewEntryViewController *viewController = [[NewEntryViewController alloc]
initWithStyle:UITableViewStyleGrouped];
viewController.parentController = self;
UINavigationController *detailNavController = [[UINavigationController alloc]
initWithRootViewController:viewController];
[UIView beginAnimations:nil context:NULL];
[self.navigationController presentModalViewController:detailNavController animated:NO];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:sourceController.view cache:YES];
[UIView commitAnimations];
SourceController was first presented modally, that's why I'm presenting detailNavController modally. The problem with this code is that the animation takes place, but sourceController is still on top of the new detailNavController. What I would like to achieve is to have the animation and then dismiss sourceController and have detailNavController displayed.
I've finally found the solution for this, here's the updated code:
- (void)createNewEntryWithAnimation
{
// before calling this method I dismissed sourceController without animation
NewEntryViewController *viewController = [[NewEntryViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewController.parentController = self;
UINavigationController *detailNavController = [[UINavigationController alloc]
initWithRootViewController:viewController];
[UIView beginAnimations:nil context:NULL];
[self.navigationController presentModalViewController:detailNavController animated:NO];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:viewController.view.window cache:NO];
[UIView commitAnimations];
}
I had to use cache:NO, otherwise the transition wasn't smooth.

iPhone view appearing behind animation

I have set up a multiview application with two views. The views can be switched using a button in each view (there are two separate actions). I am using the animation UIViewAnimationTransitionFlipFromRight, and when I go from the first to the second view, the view I am going to appears behind the flipping animation. I would like it just to be white. Any help is appreciated.
alt text http://img35.imageshack.us/img35/9982/picture11wu.png
This is the action switching the views:
- (IBAction)switchViewsOne:(id)sender
{
if (self.uLViewController == nil)
{
ULViewController *uLController =
[[ULViewController alloc]
initWithNibName:#"ULView"
bundle:nil];
self.uLViewController = uLController;
[uLController release];
}
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
UIViewController *comming = nil;
UIViewController *going = nil;
UIViewAnimationTransition transition;
if (uLViewController.view.superview == nil)
{
comming = uLViewController;
going = mainViewController;
transition = UIViewAnimationTransitionFlipFromLeft;
}
[UIView setAnimationTransition: transition forView:self.view
cache:YES];
[comming viewWillAppear:YES];
[going viewWillDisappear:YES];
[going.view removeFromSuperview];
[self.view insertSubview: comming.view atIndex:10];
[going viewDidDisappear:YES];
[comming viewDidAppear:YES];
[UIView commitAnimations];
}
You could try using addSubView which just adds it to the top of the stack.
This kind of bug can be if comming.view is nil
[self.view insertSubview: comming.view atIndex:10];
Check, maybe your nib isn't loaded properly
ULViewController *uLController = [[ULViewController alloc] initWithNibName:#"ULView" bundle:nil];
NSLog(#"Loaded controller %#:", uLController);

Flip View Iphone

please consider the code below, and tell me what I'm doing wrong.
I want to flip between two UIViews.
Somehow, when I flip away from the initial view, I just get the flipped view, without animation. When I flip back, the animation shows just fine.
The flips are triggered from buttons on the views themselves.
- (IBAction)showMoreInfo:(id)sender
{
UIView *moreInfo = self.flipView;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
[parent addSubview:moreInfo];
[UIView commitAnimations];
}
- (IBAction)showLessInfo:(id)sender
{
UIView *lessInfo = self.view;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.flipView cache:YES];
UIView *parent = self.flipView.superview;
[self.flipView removeFromSuperview];
[parent addSubview:lessInfo];
[UIView commitAnimations];
}
It's probably because you aren't using a container view as the transition view. Refer to the documentation on setAnimationTransition:forView:cache:
If you want to change the appearance of a view during a transition—for example, flip from one view to another—then use a container view, an instance of UIView, as follows:
Begin an animation block.
Set the transition on the container view.
Remove the subview from the container view.
Add the new subview to the container view.
Commit the animation block.
Try using self.view.superview in the animation transition view of the showMoreInfo:
The reason the showLessInfo: method works is you are using a container view.
Can you use your MainWindow (UIWindow) as the container view as UIWindow inherence from UIView?
Also iPhone 3.0 introduced the flip transaction via the presentModalViewController method:
CustomViewController *vc = [[CustomViewController alloc]
initWithNibName:#"CustomViewController" bundle:nil];
vc.delegate = self;
// The magic statement. This will flip from right to left.
// present the modal view controller then when you dismissModalViewController
// it will transition flip from left to right. Simple and elegant.
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:vc animated:YES];
[vc release];
After iOS 4.0, you can flip between views with this:
[UIView transitionFromView:sourceView toView:destinationView duration:0.35f options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
NSLog(#"I just flipped!");
}];
As Jason mentioned, you'll need this to occur within a container view.