I want to slide a UITableVIew into a view (NOT by pushing the view on top of Navigation Controller) on click of a button and then hide it back by sliding , on clicking of the same button.
I want the tableView to slide inside a present view.
You animate the frame property of the table view to move it off screen or back onto screen.
Here is some sample code that moves a table view off screen and moves another on screen in its place:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:kSlideTableDuration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(tableAnimationDidStop:finished:context:)];
self.tableView1.frame = offScreen;
self.tableView2.frame = onScreen;
[UIView commitAnimations];
You can read about animation blocks like this in the UIView documentation.
Check out the documentation of UINavigationController. To implement you would do something similar to this:
iPhoneCustomViewController *newView = [[iPhoneCustomViewController alloc] initWithNibName:#"iPhoneCustomViewController" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];
[newView release];
Then, when your done with the CustomViewController do:
[self.navigationController popViewControllerAnimated:YES];
You get the nice slide animations for free if you use a UINavigationController. It will take care of sliding views in (push them on the navigation controller stack) and sliding them out (pop them off the navigation controller stack).
Related
I need to somehow check in the code if by clicking a button (doing an action), it is getting the view controller's view toggled
I am using
if ([currentViewController.view respondsToSelector:#selector(setAnimationTransition:forView:cache:)])
but this one doesn't look like working
Usually this code used to get the view toggled
[UIView beginAnimations:Nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self cache:YES];
[mainView removeFromSuperview];
[self addSubview:infoView];
[UIView commitAnimations];
It looks like you're having the view controller's view manage the flipping. I'm sure that can work, but it's more common to let the view controller manage that sort of thing. If you do that, then the view controller will know when the view has been flipped, because it did the flipping.
If you're going to stick with having the view controller's view manage the transition, then you'll have to have the view controller ask its view about the state of the interface. From your view controller, you'd do something like:
BOOL flipped = [self.view isInterfaceFlipped];
To put it simply, I've built an app which started without a Navigation Controller so everything was controlled through my ViewController. Since adding the Navigation Controller, I added a button to flip to my main Navigation Controller window from my ViewController. However, when I push the button, it reloads the same window with the Navigation Bar now across the top(I hid it in the original view). If I push the same button again, it then loads the proper view. What did I do wrong to cause this loop?
My button's code below
-(IBAction) btnSettings_Clicked: (id) sender {
self.navigationController.navigationBarHidden = FALSE;
[UIView beginAnimations:#"Flip View" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
MyAppDelegate* appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[self.navigationController view] cache:YES];
[UIView commitAnimations];
[appDelegate.navigationController popViewControllerAnimated:NO]; }
If this code is in ViewController and, as you say, this controller is not pushed on a navigation controller, then the error is:
[self.navigationController view] ;
because there are no navigation controller for self. You have to replace it with:
[appDelegate.navigationController view] ;
As I asume that is the correct navigation controller to use.
And then, why are you popping the top view controller? If you want to remove self.view, then you only have to do it:
[self.view removeFromSuperview];
I believe it is this line
[self.navigationController view]
You should set the animation to the controller you wish to show and not to the current controller.
Is it possible to create a viewcontroller that could handle 5 views?
And is it possible to implement a different button on every view to make a transition to root view?
So my idea of the app is when I load it it takes me to main window, and on that window there will be 5 button that will take me to the 5 views, and after I'm in that view, among other buttons there will be just one button that will take me only to the MainView.
Let's say that some of those 5 views will be Options, Score, Statistics, something like that.
If it is possible to make an app like that using so much views, is it a good approach?
This would be possible, but from what you describe, it does not sound like a good idea. I would suggest instead making a Tab Bar app, and having a separate view controller for each of your 5 views.
If you do not want to make a tab bar app, you can certainly do what you describe, but I would recommend having a separate view controller instance for each view. You could have your 5 buttons in your main view, and each button could push a modal view with no animation. You could then add whatever transition animation you want. In your modal view, you could have a button that pops the modal view.
In your main view controller, you would do this:
- (IBAction)button1Click {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
UIViewController *newController = [[UIViewController alloc] initWithNibName:#"View1" bundle:nil];
[self presentModalViewController:newController animated:NO];
[newController release];
[UIView commitAnimations];
}
And in your view 1 controller:
- (IBAction)backToMainClick {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self dismissModalViewControllerAnimated:NO];
[UIView commitAnimations];
}
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];
I have a small problem with UINavigationController animation between two view.
My application build more than two view,
first view contains login information, second view contains root menu, last view contains sample data and so on..
My MainWindow.xib contains a UINavigationController component which is contains all navigation structure.
When my login view loaded, i use this lines of code
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
for hide UINavugationConttoller (I don't need to show to user navigation bar during the login.)
After that when the user execute the login submit button on the login view
i use this code for push the RootmenuView to the UINavigationController's stack.
RootMenuController *rootMenuController = [[RootMenuController alloc] initWithNibName:#"RootMenuController" bundle:0];
[self.navigationController pushViewController:rootMenuController animated:NO];
[rootMenuController release];
It's working very well. And when the Rootmenuview loaded user have to show the navigation bar then i'm showing the UINavigation's tool bar with this code
- (void)viewDidAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
But i don't like the default animation transitions of UINavigationController then i changed above code with below
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.50];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:YES];
RootMenuController *rootMenuController = [[RootMenuController alloc] initWithNibName:#"RootMenuController" bundle:0];
[self.navigationController pushViewController:rootMenuController animated:NO];
[UIView commitAnimations];
[rootMenuController release];
It's working too but UINavigationController flickering during between two view naimation transition.
I didn't solve this problem.
Any suggestions ?
Thank you
Have you tried [setAnimationTransition:forView:cache:NO]? I got some odd behavior similar to yours when I used to mess around with UIView animations and used caching.