presentViewController and UIViewController layout - ios

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.

Related

Transition to a view controller with a custom animation

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

How to use animateWithDuration: when presenting view controller on iOS 7?

I'm currently using the following code in order to present my view controller.
CATransition* transition = [CATransition animation];
transition.duration = 1;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromBottom;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:viewController animated:NO completion:nil];
I need to use more complex animation utilizing UIView animateWithDuration method. It is just modal presentation and background view controller should stay there. How can I animate presenting view controller's view?
Update: next version of code :)
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:NULL];
RootViewControllerEx *viewController = (RootViewControllerEx *)[sb instantiateViewControllerWithIdentifier:#"SB_RDVC"];
viewController.transitioningDelegate = self;
viewController.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:viewController animated:YES completion:nil];
...
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
...
}
VC in storyboard doesn't have any segue specified, it stays lonely in storyboard :)
You need to use UIModalPresentationCustom as your UIViewController's modalPresentationStyle.
You then need to create a class that conforms to the UIViewControllerTransitioningDelegate and set that your on presentedViewController.
Example
YourViewController *viewController = [[YourViewController alloc] init];
viewController.delegate = self;
viewController.transitioningDelegate = self;
viewController.modalPresentationStyle = UIModalPresentationCustom;
[self.navigationController presentViewController:viewController animated:YES completion:nil];
You must then implement the following method:
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source;
Which returns an object that conforms to a UIViewControllerAnimatedTransitioning protocol, that implements the following method:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIView *inView = [transitionContext containerView];
UIView *toView = [[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey] view];
toView.frame = //CGRectMake(0,0,0,0);
[inView addSubview:toView];
// Use whatever animateWithDuration you need
[UIView animateWithDuration:0.6f delay:0.0f usingSpringWithDamping:0.7f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseIn animations:^{
// Custom animation here
} completion:^(BOOL finished) {
// IMPORTANT
[transitionContext completeTransition:YES];
}];
}
Always remember to tell the context when a transition is complete, otherwise you'll enter an unstable state.

Shift to Parent View Controller from child view controller - iOS

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

IOS: custom transition for a viewController

I have this code in my app to do a transition for a viewcontroller
SecondViewController *second = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.view addSubview:second.view];
[second.view setFrame:CGRectMake(320, 0, 320, 480)];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.40]; //the double represents seconds
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[second.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
and it work fine;
but inside second view controller I have this code to disappear this viewcontroller
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.40]; //the double represents seconds
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.view setFrame:CGRectMake(320, 0, 320, 480)];
[UIView commitAnimations];
it work fine, but what's the way to release it, where can I release this second that I alloc when I call it??
if I write [self.view removeFromSuperView]?? is it released??
You need to remove it from the superView then release the SecondViewController that you allocated in your code.
SecondViewController *second = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
So since you are owning this object you need to release it.
So somewhere after hiding the second view, and removing it from superView, you need to release it...
[second release];

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];
alarmViewController = [[AlarmViewController alloc] init];
[self.navigationController pushViewController:alarmViewController animated:YES];
[alarmViewController release];
[UIView commitAnimations];
I just want the viewcontroller flip like opening a book page,but it does not work like this.And I have a question that whether navigationController can animate this effect?
Since you are already putting the navigationController in an animation block. Mark animated:NO -
[self.navigationController pushViewController:alarmViewController animated:NO];
when we actually call pushViewController: we are setting the animated value to NO. This disables the Navigation Controller's default animation. Instead, the block of code uses the defined transition.

Resources