I want transition similar to UIPageViewController transistion, Is it possible to achieve it.
SecondViewController* bvc = [[SecondViewController alloc] init];
[UIView transitionWithView:self.view.window
duration:1.0f
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.navigationController pushViewController:bvc animated:NO];
}
completion:NULL];
[self.navigationController pushViewController:bvc animated:YES];
As If now I have pageCurl(up) achieved via above code. But Actually want transition like pageTurn side wise. Any way to achieve this?
Related
How to load multiple views one after the another once this view is displayed
- (void)displayviewsAction:(id)sender
{
PageOneViewController *viewController = [[[PageOneViewController alloc] init]autorelease];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
}
Now on top of this viewcontroller how i can load multiple viewcontrollers one after the other.
Please advice.
Thanks for help.
It depends on how you want to display it. If you're using a UINavigationController, you can do something like:
[self.navigationController pushViewController:viewController animated:YES];
or, if you'd like to present it as a modal view, you can do this to support older versions of iOS:
[self presentModalViewController:viewController animated:YES];
or, if you're only targeting iOS 5, do this:
[self presentViewController:viewController animated:YES completion:NULL];
Then to dismiss the view controller, on older versions of iOS:
[self dismissModalViewControllerAnimated:YES];
or if you're only targeting iOS 5:
[self dismissViewControllerAnimated:YES completion:NULL];
I think what you are looking for is a UINavigationController. That is a kind of super-controller that can load a stack of other view controllers one after another.
I am using the following code to animate a view on to another view. it works but only the navigation bar items are being animated the rest of the view just appears. I have tested on iphone and iphone simulator same problem on both. I would like the whole view to curl in not just the buttons.
loginView = [[loginController alloc] initWithNibName:#"login" bundle:[NSBundle mainBundle]];
UIView *containerView = self.view;
[UIView transitionWithView:containerView
duration:2.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{ [containerView addSubview:loginView.view]; }
completion:NULL];
}
You speed up the animation duration which is default 3.0 so that it act like that
I have two views: one has just a button (view 1) and the other contains a tableview with a search bar (screen2). When the user clicks that button in view 1, I want view 1 to flip and display screen 2.
View 2 resides inside of the navigational controller with a navigation bar on top.
Below is what I have for now. The transition animation works and flips to the second screen but view 2 is missing the SearchBar and title from NavigationBar. Both are set inside view 2.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
navigationController = [[UINavigationController alloc] init];
bestbuyProducts = [[BestBuyProductsViewController alloc] initWithNibName:#"BestBuyProductsViewController" bundle:nil];
[navigationController pushViewController:bestbuyProducts animated:NO];
[navigationController.view setFrame: [self.view bounds]];
[bestbuyProducts release];
[self.view addSubview:navigationController.view];
[UIView commitAnimations];
Thank you
To start your UINavigationController is not initialise correctly. Use the initWithRootViewController: method like that:
bestbuyProducts = [[BestBuyProductsViewController alloc] initWithNibName:#"BestBuyProductsViewController" bundle:nil];
// Initialise the navigation view with the bestbuyProducts view controller
navigationController = [[UINavigationController alloc] initWithRootViewController:bestbuyProducts ];
Then try to use modal view transition to make a flip animation, It's easier and more safe to start:
[navigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[bestbuyProducts release];
OK here is the correct version
navigationController = [[UINavigationController alloc] initWithRootViewController:bestbuyProducts];
[bestbuyProducts setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navigationController animated:YES];
I have an app that has a centre view with two views off to each side of it. I want to have two navigation bar buttons, left and right which push a new navigation controller onto the view from the left or the right.
When you change views by pushing a new view using the pushviewController: method of NavigationController, the view appears to slide in from the right. how do i change this to slide in from the left?
I have done change animation direction when we push viewcontroller.
you can change animation type here [animation setSubtype:kCATransitionFromRight];
ViewController *elementController = [[ViewController alloc] init];
// set the element for the controller
ViewController.element = element;
// push the element view controller onto the navigation stack to display it
CATransition *animation = [CATransition animation];
[[self navigationController] pushViewController:elementController animated:NO];
[animation setDuration:0.45];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[elementController.view layer] addAnimation:animation forKey:#"SwitchToView1"];
[elementController release];
Instead of using a navigation controller, I would just move the view.
CGRect inFrame = [currentView frame];
CGRect outFrame = firstFrame;
outFrame.origin.x -= inFrame.size.width;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[newView setFrame:inFrame];
currentView setFrame:outFrame];
[UIView commitAnimations];
I don't think you can explicitly define sliding direction in UINavigationControllers. What you might be able to do is pop the current view off the navigation stack to show the prior view, which would animate in the manner you want. However this may be complex if you want to have different view controllers appear depending on what you do on the current view.
If your workflow is not too complicated, you can hold a reference to the prior view controller in the current view controller. depending on what you do on the current view (like select a table view cell), you can change whatever data you need in the prior view controller, and then call
[self.navigationController popViewController];
or whatever the correct method is (i think that's pretty close to how it is). that would let you move down the nav stack with the animation you want, which works if your nav stack has a set number of views on it.
to what Reed Olsen said: you must only hook up one button, that starts the slide up to the same method and add a BOOL that tracks if the view is shown or not. all you need to do is set the origin properly.
- (IBAction)slideMenuView
{
CGRect inFrame = [self.view frame];
CGRect outFrame = self.view.frame;
if (self.viewisHidden) {
outFrame.origin.x += inFrame.size.width-50;
self.viewisHidden = NO;
} else {
outFrame.origin.x -= inFrame.size.width-50;
self.viewisHidden = YES;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.menuView setFrame:inFrame];
[self.view setFrame:outFrame];
[UIView commitAnimations];
}
To get the "pointy" type button you need to use a different method.
In your AppDelegate:
UITableViewController *first = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
UITableViewController *second = [[SomeOtherViewController alloc] initWithStyle:UITableViewStylePlain];
NSArray *stack = [NSArray arrayWithObjects: first, second, nil];
UINavigationController *nav = [[UINavigationController alloc] init];
[nav setViewControllers:stack animated:NO];
You can inherit RTLNavigationController:UINavigationController and overwrite these functions.
- (void) pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
DummyViewController*dvc = [[DummyViewController alloc] init];
[super pushViewController:viewController animated:NO];
[super pushViewController:dvc animated:NO];
[dvc release];
[super popViewControllerAnimated:YES];
}
and
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
UIViewController *firstViewController = [super popViewControllerAnimated:NO];
UIViewController *viewController = [super popViewControllerAnimated:NO];
[super pushViewController:viewController animated:animated];
return firstViewController;
}
And in application delegate:
navCon = [[RTLNavigationController alloc] init];
rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
rootViewController.contextDelegate = self;
DummyViewController *dvc = [[DummyViewController alloc]init];
[navCon pushViewController:dvc animated:NO];
[dvc release];
[navCon pushViewController:rootViewController animated:NO];
[self.window addSubview:navCon.view];
Pushing will be from left to right and popping from right to left
I'm currently displaying a UIViewController like this:
[[self navigationController] presentModalViewController:modalViewController animated:YES];
and hiding it like this:
[self.navigationController dismissModalViewControllerAnimated:YES];
The animation is "slide up from the bottom"... then slide back down. How can I change the animation style? Can I made it fade in/out?
Cheers!
For iPhone 3.0+, a basic crossfade is easiest to do like this:
modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[[self navigationController] presentModalViewController:modalViewController
animated:YES];
Marcus Zarra posted a great solution to this on the SDK mailing list:
UIViewController *controller = [[[MyViewController alloc] init] autorelease];
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[navController presentModalViewController: controller animated: NO];
[UIView commitAnimations];
There are transitions for flipping and page-curling. If you are set on fading, can try adjusting your new view's alpha:
UIViewController *controller = [[[MyViewController alloc] init] autorelease];
controller.view.alpha = 0.0;
[navController presentModalViewController: controller animated: NO];
[UIView beginAnimations: nil context: nil];
controller.view.alpha = 1.0;
[UIView commitAnimations];
However, what you probably want is a crossfade, or at least a fade-over. When the UINavigationController switches to a new view, it removes the old one. For this effect, you're probably better off just adding a new view to your existing UIViewController and fading its alpha in over time.
Note: If you are not in your app delegate [self window] will not work. Use self.view.window , thanks to user412500's post for pointing this out.
To update for alpha fading in iOS 4:
modalController.view.alpha = 0.0;
[self.view.window.rootViewController presentModalViewController:modalController animated:NO];
[UIView animateWithDuration:0.5
animations:^{modalController.view.alpha = 1.0;}];
It should be [self.view.window] in order for the code to work
(at least that's the way that it is in ios 3.2)