I am trying to create a scale animation for my view controller presentation
what i have is
UIViewController *vc =[[UIViewController alloc]initWithNibName:#"nextVC" bundle:[NSBundle mainBundle]];
[vc willMoveToParentViewController:self];
[self addChildViewController:vc];
[self transitionFromViewController:currentViewController toViewController:vc duration:2 options:0 animations:^(void){
vc.view.layer.anchorPoint = currentViewController.view.frame.origin;
vc.view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
vc.view.frame = currentViewController.view.frame;
}completion:^(BOOL finished){
[vc didMoveToParentViewController:self];
}];
now this code works, the view controller is presented.
but instead of doing the right scale i want, it comes flying in from the bottom right corner.
how do i make it sort of unfold from the top margin to the bottom margin
Related
I am pushing a view controller whilst animating it so it flips. However, the animation is only applied to the view beneath the navigation bar, so the navigation bar hides for a few seconds then suddenly appears again. How can I apply the animation to the entire view, including the navigation bar?
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"OverviewiPad" bundle:nil];
OverviewViewController *overviewVC = [sb instantiateViewControllerWithIdentifier:#"OverviewViewController"];
overviewVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:overviewVC animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
I'm using a custom flip transition during a push transition.
I use this code and the flip is good:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MyViewController* myViewController = [sb instantiateViewControllerWithIdentifier:
#"MyViewController"];
[UIView transitionWithView:self.navigationController.view
duration:0.75
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.navigationController pushViewController:myViewController animated:NO];
}
completion:nil];
The problem is during the transition. I have a kind of shadow on all the window view. I can change the color but the shadow stays. An example with a red background ([UIColor RedColor]):
Thank you
I have a UIViewController that has a parent UITabBarController.
At the start the UIViewController is located above the UITabBarController. after returning from the call to address book the UIViewController is located below it (its height increased suddenly)
the call is [self presentViewController:picker animated:YES completion:nil]
picker is the ABPeoplePickerNavigationController
Thanks, roi
Its very different to say, what you need, we have no some your code, but I try to help:
Try to change [self presentViewController:picker animated:YES completion:nil] on
[self.navigationController presentViewController:picker animated:YES completion:nil]
//or [anyNavController presentViewController:picker animated:YES completion:nil]
If it's not help, try to set ViewController's view (which presenting) height in viewDidLoad
Or you can try to presenting newView without navigation controller:
newView.bounds = mainView.bounds; //newView can be nextViewController.view
newView.biunds.size.height=newView.biunds.size.height- self.navBar.bounds.size.height;//devide navBar height (you can delete this line)
newView.frame = CGRectMake(newView.frame.origin.x + 784, newView.frame.origin.y, newView.frame.size.width, newView.frame.size.height);
[mainView addSubview:newView];
/* Begin transition */
[UIView beginAnimations:#"Slide Left" context:oldView];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.0f];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDidStopSelector:#selector(slideInCompleted:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
newView.frame = CGRectMake(0,0, newView.frame.size.width, newView.frame.size.height);
oldView.frame = CGRectMake(oldView.frame.origin.x - 784, oldView.frame.origin.y, oldView.frame.size.width, oldView.frame.size.height);
[UIView commitAnimations];
Post comments, how is your result.
I have a main Actions View Controller, and on that there is button "Review". Review Button's functionality is :
- (IBAction)btnReview:(id)sender
{
ReviewViewController *vc = [[ReviewViewController alloc]initWithNibName:#"ReviewViewController" bundle:nil];
[self addChildViewController:vc];
[vc didMoveToParentViewController:self];
[self.view addSubview:vc.view];
}
Now on Review Page, I have a button. And on that button's action, I want to switch back to Parent View Controller. Its view should be displayed. I have tried following code, it either pauses or crashes application.
[self didMoveToParentViewController:nil];
[self.view removeFromSuperview];
[self removeFromParentViewController];
I even tried:
[self dismissModalViewControllerAnimated:YES]
I have read other posts related to this question as well but could not find a satisfactory answer. Please Help!
I'm assuming that this is a custom viewcontroller container you're trying to build, "self" is the Main Actions viewController you're talking about.
Try this:
- (IBAction)btnReview:(id)sender
{
ReviewViewController *vc = [[ReviewViewController alloc]initWithNibName:#"ReviewViewController" bundle:nil];
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[vc didMoveToParentViewController:self];
vc = nil;
}
For the "Back" button, I'm assuming this is the Button to return to Main Actions viewController from the Review viewController, try this:
- (IBAction)btnReviewHide:(id)sender
{
[self willMoveToParentViewController:nil];
[self.view removeFromSuperview];
[self removeFromParentViewController];
}
Hope this helps.
You should use delegation. When you click the button in your ReviewViewController, you call a method like: [self.delegate hideReviewController:self];
And this method would look something like:
- (void)hideReviewController:(ReviewViewController *)controller {
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
controller.view.alpha = 0;
} completion:^(BOOL finished) {
[self.view removeSubview:controller.view];
// If you want the Review Controller to be deallocated:
[self removeChildViewController:controller];
}];
}
EDIT:
In your ReviewDelegate.h file add:
#class ReviewViewController;
#protocol ReviewDelegate <NSObject>
- (void)hideReviewController:(ReviewViewController *)controller;
#end
Then add this property:
#property (nonatomic, weak) id <ReviewDelegate> delegate;
In the parent class:
- (IBAction)btnReview:(id)sender
{
ReviewViewController *vc = [[ReviewViewController alloc]initWithNibName:#"ReviewViewController" bundle:nil];
vc.delegate = self;
[self addChildViewController:vc];
[vc didMoveToParentViewController:self];
[self.view addSubview:vc.view];
}
- (void)hideReviewController:(ReviewViewController *)controller {
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
controller.view.alpha = 0;
} completion:^(BOOL finished) {
[self.view removeSubview:controller.view];
// If you want the Review Controller to be deallocated:
[self removeChildViewController:controller];
}];
}
I also suggest that you read about delegation
Try this
self.view=nil;
[self willMoveToParentViewController:nil];
[self.view removeFromSuperview];
[self removeFromParentViewController];
You don't need to make it complex... Just use UINavigationController.
To navigate from ParentVC to ChildVC :
ChildViewController *ChildVC = [[ChildViewController alloc]initWithNibName:#"ChildViewController" bundle:nil];
[self.navigationController pushViewController:ChildVC animated:YES];
And for navigating back from ChildVC to ParentVC :
ParentViewController *ParentVC = [[ParentViewController alloc]initWithNibName:#"ParentViewController" bundle:nil];
[self.navigationController popViewControllerAnimated:YES];
Since you are adding the Child View as a Subview on to Parent you need to manually it from its superview (in your case parentview). Rather then adding it as a subview you can make use of presentViewController method as follow:
- (IBAction)btnReview:(id)sender
{
ReviewViewController *vc = [[ReviewViewController alloc] initWithNibName:#"ReviewViewController" bundle:nil];
[self presentViewController:vc
animated:YES
completion:nil];
}
and in the child class code for back button will be :
-(IBAction)backButtonClicked:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Sounds like what you're looking for could be taken care of with a UINavigationController. Just use pushViewController: to push the new view onto the screen. Then, a back button will appear in the navigation bar atop the view, which can be used to return to the "parent" view controller.
See the documentation.
writing only
- (IBAction)backbutton:(id)sender {
[self.navigationController popToRootViewControllerAnimated:YES];
}
worked in my case
I'm pushing a view controller that contains a tableiview onto my uinavigation controller:
CourseMenuViewController *mvc = [[[CourseMenuViewController alloc] initWithSlidingNavigationcontroller:self.slidingNavigationController] autorelease];
mvc.course = course;
[self.navigationController pushViewController:mvc animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:NO];
So far so good, everything works as expected. My issue occurs when I watch the animation and see all of my table view rows animate down from the top of the screen as the view is animating in from the left. This makes it feel like the view is moving from the top-left corner to the bottom-right corner in a diagonal path.
My question is, how can I make the table view just appear instead of animating? I should add that all of my cells are static so I'm not waiting on any data from a NSFetchedResultsController or anything like that.
roronoa below put me on the right path, and here is the now working version:
CourseMenuViewController *mvc = [[[CourseMenuViewController alloc] initWithSlidingNavigationcontroller:self.slidingNavigationController] autorelease];
mvc.course = course;
CATransition *caTransition = [CATransition animation];
caTransition.duration = 0.35;
caTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
caTransition.delegate = self;
caTransition.type = kCATransitionPush;
caTransition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:caTransition forKey:nil];
[self.navigationController pushViewController:mvc animated:NO];
You have not mentioned details about your class CourseMenuViewController and initWithSlidingNavigationcontroller , but you can use the following to get the job done:-
CourseMenuViewController *mvc =[[CourseMenuViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self.navigationController pushViewController:mvc animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[mvc release];
you can have any type of animation that you want in the above code by changing the animation constants according to your need without having unwanted animations on your tableview.