iPhone Modal view transition. Flip opposite way? - iphone

using the transition, UIModalTransitionStyleFlipHorizontal seems to flip from right to left when initialized and left to right when returning.
Is there any way to make it flip the opposite way?

Try this... transition the views first and when it completes, then present the modal view controller (not animated)
ModalViewController *modalViewController = [ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[UIView transitionFromView:self.view toView:modalViewController.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished){
if (finished) {
[self presentViewController:modalViewController animated:NO completion:nil];
}
}];

Not if you're using the modalTransitionStyle property.
If you want to do it you'd probably have to animate it yourself.
These are all the possible transition styles that you can use.

Related

Replace window.rootViewController with animation works partially

I'm trying to replace the window rootViewController with animation and it only works partially.
I create a UINavigationController programatically -
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"InboxStoryboard" bundle:nil];
UIViewController *innerViewController = [storyBoard instantiateViewControllerWithIdentifier:#"centerView"];
UINavigationController *centerView = [[UINavigationController alloc] initWithRootViewController:innerViewController];
Afterwards I replace the window root view controller wrapped in an animation block -
[UIView transitionWithView:self.viewController.view.window
duration:0.5
options: UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
self.viewController.view.window.rootViewController = centerView;
}
completion:nil];
What happens is that the animation happen but the controller that I create is only partially visible, take a look at the following picture -
So as you can see during the rotation the view is only partially rendered.
Anyone bumped into this kind of behaviour before?
So after a long search I found the problem was in the [UIView transitionWithView:...]
Searching a bit more in stackoverflow I found Swapping rootViewController with animation
Using [UIView transitionFromView:..] works perfectly.
The new code -
[UIView transitionFromView:self.window.rootViewController.view
toView:self.centerViewController.view
duration:0.5
options:UIViewAnimationOptionTransitionCurlUp
completion:^(BOOL finished)
{
self.window.rootViewController = self.centerViewController;
}];
Are you using Auto layout? If so, try disabling it. I have run into multiple problems with auto layout and animations.

Animate the process of tab switching

Anyone have a walk around on animating the process when switching tabs?
I am currently doing this with 2 issues.
1: It messes up my UIControl colors.
2: It switches the tab first, thereafter perform the animation.
I want to implement something like the effect when pushing a view to navigation stack.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:bookingVC.view cache:YES];
[UIView commitAnimations];
[self.tabBarController setSelectedIndex:0];
Right now I am doing this, which doesn't have any animation effect.
NSArray *tabBarVC = [self.tabBarController viewControllers];
UINavigationController *firstTabNC = [tabBarVC objectAtIndex:0];
BookingViewController *bookingVC = (BookingViewController *)[[firstTabNC viewControllers] objectAtIndex:0];
[bookingVC setNSStringProperty:newString]; //this string will be displayed on a UITextField whenever viewDidAppear;
// So, I need some animation here when I switch tabs to make it more obvious that the UITextField is updated.
[self.tabBarController setSelectedIndex:0];
I am totally clueless on creating my own animation, please do guide me along. I am opened to ideas to better the presentation.
Thanks.
Any reason you need to use the pre-iOS4 way of animating? Animation blocks simplify this:
[UIView animateWithDuration:1.0
delay:0
options:UIViewAnimationOptionTransitionCurlUp
animations:
^{
// show your desired view however you do it
}
completion:
^(BOOL finished) {
[self.tabBarController setSelectedIndex:0];
}];
EDIT: Sorry, I didn't pick up you were doing a view transition somehow.. silly. There's another block-based method for that case:
[UIView transitionWithView:bookingVC.view
duration:1.0
options:UIViewAnimationOptionsTransitionCurlUp
animations:
^{
// do view transitioning here
}
completion:
^(BOOL finished) {
[self.tabBarController setSelectedIndex:0];
}];
EDIT 2: Alright, so you seem to need some help with the context of all this. You should be animating changes to active tabs in the UITabBarControllerDelegate protocol (which your custom class would implement). In particular, the tabBarController:didSelectViewController: method.
I'd recommend you first override the tabBarController:shouldSelectViewController: method to make sure that you don't accidentally animate a transition from a tab to the same tab:
- (BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController
{
return viewController != [tabBarController selectedViewController];
}
In didSelectViewController:, do the animation. I'm also going to take this opportunity to rework your code, because if you're doing it within this method then the selectedIndex of the tab bar controller is handled automatically, and whatever you were doing with bookingVC.view can be replaced by a direct transition between the active tab controller and the new (selected) one:
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
[UIView transitionFromView:[tabBarController selectedViewController].view
toView:viewController.view
duration:1.0
options:UIViewAnimationOptionsTransitionCurlUp |
UIViewAnimationOptionsShowHideTransitionViews
completion:nil];
}
Note here that I use UIViewAnimationOptionsShowHideTransitionViews as part of your animation options. I'm doing this because our animation is on top of the system already changing the active tab, so we don't want to muck it up by trying to remove the view from the view heirarchy at the same time as the system is.
Try placing your animation sequence in didSelectItem::
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;
Then set up a modalView controller and animate the page curl effect from there.

Iphone dismissModalViewController animation

How can I modify the animation for dismiss?
for present, I've used :
SlideShow *slider = [[SlideShow alloc] initWithNibName:#"SlideShow" bundle:nil];
slider.view.alpha = 0.0;
[self presentModalViewController: slider animated: NO];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
slider.view.alpha = 1.0;
[UIView commitAnimations];
and it works..
But how about a way to dismiss it using a custom animation (I was looking for a Fade-Out animation for dismiss)
Thanks.
You are fading view controllers the old school way, since iOS 3 the easiest and best way to fade a view controller is to set its property: (ex. in the init method)
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
Your view controller will then fade nicely in and out.
presentModalViewController is essentially a method that serves up a pre-baked animation for your viewController.view. If you want to make a custom animation for dismissing or presenting a modal view, you have to handle it all on your own.

Flip View error - accessing unknown getter method

I am having a view called NView on which I am having a design button clicking on which I want another view DView in flipview, but it's not working. Below is my code. I got an error called accessing unknown getter method:
NSLog(#"yuppii");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:([NView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView: DView cache:YES];
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:
1. Begin an animation block.
2. Set the transition on the container view.
3. Remove the subview from the container view.
4. Add the new subview to the container view.
5. 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.
or use this way-may be helped u......
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];

flip viewController only flips the first time

I am flipping over to an info view on the backside. I have it flipping, and I have a navigation bar on the other side to get me back home to the original view (which was a problem when I was trying to use a modal).
My problem now is that it only works the first time: I tap the info button, I flip to the backside. I tap the back button and I can flip back no problem.
But, if I tap that info button again, it pushes over to the info view instead of flipping. The flip back is still fine. If I leave the root view and go elsewhere and come back, it flips properly again.
In the method that is invoked when I click the info button:
InfoViewController *controller = [[[InfoViewController alloc] init] autorelease];
[UIView beginAnimations:#"animation" context:nil];
[self.navigationController pushViewController: controller animated:NO];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Thanks for your help!
where you initializing InfoViewController ?
as every time you come on the Root it's getting initialize and working fine...
When you click back it doesn't.... so easy fix will be write this code in viewWillAppear...which gets called every time you visit the view..
Hope this helps..
Here is a bit newer implementation which uses blocks from newer UIView APIs and relies on ARC.
This is how you push new flipping screen:
InfoViewController *controller = [[InfoViewController alloc] init];
[self.navigationController pushViewController:controller animated:NO];
[UIView transitionFromView:self.view
toView:controller.view
duration:0.8f
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
// Add completion stuff here
}];
And here is the snippet for dismissing it:
[self.navigationController popViewControllerAnimated:NO];
[UIView transitionFromView:controller.view
toView:self.view duration:0.8f
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
// Add completion stuff here
}];