UITabController flip - iphone

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;
}];

Related

Push ViewController with modal animation (horizontal flip)

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.

pushViewController without title animation

I push Viewcontroller using this code:
if (! self.infoViewController) {
self.infoViewController = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
}
[UIView animateWithDuration:0.7f
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[self.navigationController pushViewController:self.infoViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
}];
Is it possible to disable navigationBar title animation? It's slide from left during animation.
Push your ViewController without animation like this:
if (! self.infoViewController) {
self.infoViewController = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
}
[self.navigationController pushViewController:self.infoViewController animated:NO];
this will not animate ur pushing title. I hope this will helps u.
I'm sorry. Here is the answer:
[UIView animateWithDuration:0.7f
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
}];
[self.navigationController pushViewController:self.infoViewController animated:NO];

How to change view on button click in iPhone without navigation controller?

I want to know how to change view on button click in iPhone without navigation controller?
If you're doing this with a UIViewController, you would probably do this like following:
- (IBAction)change {
UIViewController* viewController = [[UIViewController alloc] init];
[self.view addSubView];
// Save the UIViewController somewhere if necessary, otherwise release it
}
Not sure why you don't want to use a UINavigationController though. If it's the navigation bar at the top you don't want to see, there's a property for that so you can hide that bar. Not sure about it's name, probably navigationBarHidden or something like that. You can look that up in the API.
There are many different ways you can do that, and you should possibly provide more information about your app.
A generic way to do it is the following, with animation:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[vc1 viewWillDisappear:YES];
[vc2 viewWillAppear:YES];
vc1.view.hidden = YES;
vc2.view.hidden = NO;
[vc1 viewDidDisappear:YES];
[vc2 viewDidAppear:YES];
[UIView commitAnimations];
In this case, both views are there, you only hide/show them as you need. Alternatively, you could add/remove the view from their superview:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[vc1 viewWillDisappear:YES];
[vc2 viewWillAppear:YES];
[vc1 removeFromSuperview];
[masterController.view addSubview:vc2.view;
[vc1 viewDidDisappear:YES];
[vc2 viewDidAppear:YES];
[UIView commitAnimations];
Place this in Button IBAction method
[mCurrentView removeFromSuperview];
[self.view addSubView:mNewView];
Assume you have two view myView1 and myView2 and one button myUIButton in memory
myView1.tag = 1;
myView2.tag = 2;
myUIButton.tag = 1; //Current visible view is myView1
-(void) ButtonCLicked:(id) sender
{
UIButton* myButton = (UIButton*)sender;
if(sender.tag == 1)
{
[myView1 removeFromSuperview];
[self addSubview:myView2]
myButton.tag = myView2.tag;
}
else
{
[myView2 removeFromSuperview];
[self addSubview:myView1]
myButton.tag = myView1.tag;
}
}
You can place two UIView variables in the header file and hide/show one of them or you can make another layer over the existing view like this:
-(IBAction)changeView {
UIView *view = [[UIView alloc] initWithNibName:#"letMeSeeThis" bundle:nil];
[self.view addSubview:view];
}

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);