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
Related
I'm currently having a UIViewcontroller with a 3-segment UISegmentedControl that when clicked switches view controllers displayed. The navigation bar and tab bar of this view are translucent.
I initialize the view like this:
- (void)viewDidLoad {
[super viewDidLoad];
[self setAutomaticallyAdjustsScrollViewInsets:YES];
self.segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:#"View 1",#"View 2",#"View 3",nil]];
[self.segControl setTintColor:[[ConstantsSingleton sharedConstants] default_bg_Color]];
[self.segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[self.segControl addTarget:self action:#selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
[self.segControl setSelectedSegmentIndex:0];
self.navigationItem.titleView = self.segControl;
//Setting up the first viewcontroller
UIViewController *vc = [self viewControllerForSegmentIndex:self.segControl.selectedSegmentIndex];
[self addChildViewController:vc];
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view];
self.currentViewController = vc;
}
The contentView is a IB defined UIView with 0 leading and trailing on all sides (so basically it fills the parent view).
I switch viewcontrollers the following way:
-(void)segmentChanged:(UISegmentedControl *)sender {
UIViewController *vc = [self viewControllerForSegmentIndex:sender.selectedSegmentIndex];
[self addChildViewController:vc];
[self transitionFromViewController:self.currentViewController toViewController:vc duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
vc.view.frame = self.contentView.bounds;
[self.currentViewController.view removeFromSuperview];
[self.contentView addSubview:vc.view];
} completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[self.currentViewController removeFromParentViewController];
self.currentViewController = vc;
}];
self.navigationItem.title = vc.title;
}
Now whenever I run this with a opaque navigation bar and tab bar this works fine, but whenever I try to use a translucent navigation bar and/or tab bar only the first view gets resized/its insets adjusted properly to not be behind the translucent navigation bar and/or tab bar. The second and third view will still appear behind them when they appear on screen.
It doesn't matter which viewcontroller is set as the first viewcontroller, all lead to the same behaviour.
What could be causing this issue and is there a way to solve this without resolving to manual contentinset adjustments.
I would suggest to enable the option Extend Edges in the property inspector of you're view.
Here's a good stackoverflow post differentiating the various layout settings for iOS 7 and up:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7
I've implemented a facebook like slide menu. When I swipe the navigationBar, the "Settings" view will appear underneath.
The problem is when I try to present a modal view from the Settings view. I try to implement a feedback system (MFMailComposeViewController), but if I present it from the Settings view underneath, half of the modal view will be blocked by the overlay view (The rootView controller).
What can I do to fix this problem?
Thanks in advance
masterViewController = [[MatchTable alloc] initWithNibName:#"MatchTable" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
Settings *sideMenuViewController = [[Settings alloc] initWithNibName:#"Settings" bundle:nil];
// make sure to display the navigation controller before calling this
[MFSideMenuManager configureWithNavigationController:self.navigationController sideMenuController:sideMenuViewController];
Well i did it like this to give it a sort of animation effect..You can choose any other effect you like:
[UIView beginAnimations:#"Flip" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:appDelegate.window.rootViewController.view cache:YES];
[appDelegate.window.rootViewController.view addSubview:#"Your View Object"];
[UIView commitAnimations];
I am trying to switch views, but I want the animation with the view lifts up and its like a piece of paper folding to see what is underneath.
Any tutorials or examples of how to get that view animation, if it is an animation, would be appreciated.
Actually the view that the maps app uses when you hit the button on the corner.
Something like this should work:
MyViewController *myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
myView.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissModalViewControllerAnimated:)] autorelease];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:myView];
navigation.modalTransitionStyle = UIModalTransitionStylePartialCurl;
navigation.delegate = self;
[self presentModalViewController:navigation animated:YES];
The key here is the modalTransitionStyle property needs to be set to UIModalTransitionStylePartialCurl before presenting the modal view.
More info here: UIViewController Class Reference (look for modalPresentationStyle, modalTransitionStyle, presentModalViewController:animated:, and dismissModalViewControllerAnimated:).
There are two basic ways of doing this, the old one which is no longer recommended:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:containerView cache:YES];
[containerView addSubview:subview];
[UIView commitAnimations];
And the new one (It uses blocks which are supported from iOS 4 and on):
[UIView transitionWithView:containerView duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [containerView addSubview:subview]; }
completion:nil];
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'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)