dismiss modal view to different uiview - uiview

I have a uiview that has a subview. That subview has a button that loads a modalViewController. Then When I use [self dismissModalViewControllerAnimated:YES]; I need it to go back to the uiview with the subview, not just the subview that presents the modal view.
How can I do this?

Generally, you can remove a subview with:
[subView removeFromSuperview];
You can just call that right before your dismissModalViewControllerAnimated or use the completion:(Block) parameter if you want it to only go away after the brief animation:
[self dismissViewControllerAnimated:YES completion:^{
[subView removeFromSuperview];
}];

Related

Dismiss and Present same view controller

i have a view controller and i need to dismiss it and present it back in same time.
i had tried dismiss it and call back the view controller but not working.
[self dismissViewControllerAnimated:YES completion:nil];
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:#"Main" bundle:nil];
ExpandViewController *expandView=
[storyboard instantiateViewControllerWithIdentifier:#"ExpandViewController"];
expandView.delegate=self;
[expandView setEventDict:dict];
[self presentViewController:expandView animated:YES completion:NULL];
I am not exactly sure what outcome/functionality you are looking for in your question, but #matt is correct. However, you may be looking to have this happen seamlessly. Therefore you could use child view controllers instead of presenting the view controller using the [self presentViewController:VC animated:animate completion:nil] method.
Adding child vc:
[self addChildViewController:myVC];
[self.view addSubview:myVC.view];
[myVC didMoveToParentViewController:self];
Removing child vc:
[myVC willMoveToParentViewController:nil];
... remove subview.
You can set up a delegate between the two controllers to tell the parent when to dismiss the view to make things easy. You can also add the subviews at different indexes using [self.view insertSubview:myVC atIndex:index] or the other possible functions such as the insert above subview etc, to have one subview be added before dismissing the other to give a more seamless transition.
Hope this helps!
You can't present a view controller until the currently presented view controller has finished being dismissed. You won't know this has happened until the completion handler from your dismissal is called. Your mistake is that the completion handler is nil. Instead, provide a completion handler (in your first line), consisting of the remaining lines of your code. Thus, they will execute after the dismissal finishes.
[self dismissViewControllerAnimated:YES completion:^{
// ... the rest of your code goes in here ...
}];

Display values in ParentView after dismissViewControllerAnimated

I have 2 view parentView and SubView. I am called the subView from my parentView:
subView = [self.storyboard instantiateViewControllerWithIdentifier:#"subView"];
[self presentViewController:subView animated:YES completion:nil];
[self.view addSubview:subView.view];
In my subView I have some functionalities and storing the values in a string. I want to display these values in a label in my parentView after I dismiss the subView:
[self dismissViewControllerAnimated:YES completion:Nil];
How can I pass these values to my parentView and display it over there after dismissViewControllerAnimated?
You can have properties in your SubView and before calling [self dismissViewControllerAnimated:YES completion:Nil]; take values from SubView and show in parentView
You can set your parent view as delegate of subView and transfer values to parent view.
By the way. Why are you calling addSubview: after presentViewController: ?
EDIT
Check this answer
Hiding buttons in a UIViewController from a UIView delegate

View Controller Containment with UINavigationController

my app is navigation based, i am adding a child view controller to one of my screens like so :
[self addChildViewController:_settingsVc];
[_settingsVc didMoveToParentViewController:self];
[self.view addSubview:_settingsVc.view];
[UIView transitionFromView:self.view toView:_settingsVc.view
duration:0.6
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
_header_view.header_title.text = #"Settings";
}];
the view and animation shows great! and when i am returning like so from the presented child view controller :
[UIView transitionFromView:_settingsVc.view toView:self.view
duration:0.6
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
_header_view.header_title.text = #"Friends Locator";
}];
i goes well too... the problem is if i am entering to the child view controller and hit the back button of the UINavigationBar then i can see the bar slides out and i got black screen.
how can i manage this?
The back button is do UINavigationController pop animation. You can try add a leftBarButtonItem that set a customView which is a UIButton, and add your own back animation in the button click event.

UIImagePickerController dismiss animation

When I try to present a UIImageViewController from the table view, the starting animation is a vertical cover, which I want, but when the controller gets dismissed, the animation is a Horizontal Flip. I tried [self presentViewController:self.imageController animated:YES completion:nil]; and [self.navigationController presentViewController:self.imageController animated:YES completion:nil]; but the dismiss animation is the same in both cases. When I remove the middle view controller (i.e just navigation controller with the tableview as its root), the dismiss animation is correct (cover vertical).
Anyone know how I can get the correct dismiss animation with the current storyboard configuration?
You can try this method:
[self.navigationController pushViewController:self.imageController animated:YES];

presentViewController:animated:completion wont Animate

this is my first question so please go easy!!
I have an iOS app that has 5 tab bars, each of which contains a Navigation controller. It seems that no matter where I call presentViewController:animated:completion from, I get no animation from the transition, the presented view controller just appears on screen!
This is also happening with my UIImagePickerController that I am presenting from one of my tabs. No presenting animation, but when i dismiss it it DOES animate away!
Here is a sample of the code, sent from a code generated tab bar button, with its action hooked up to a method which simply does this..
UserRegistrationViewController *userRegistration = [[UserRegistrationViewController alloc] init];
userRegistration.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:userRegistration animated:YES completion:nil];
If anyone has ANY ideas of things that I could try I would be most grateful!
I'm assuming that you want your animation to occur during the transition between tab bar presses. If so, you have little control over that animation, as the tab bar manages the transitions for you. It looks like you're trying to achieve a cross fade between tab presses. Although you really can't fade out the old view controller, you can easily make the new view controller fade in when it appears:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Set the view to transparent before it appears.
[self.view setAlpha:0.0f];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//Make the view fade in. Set Opaque at the end for a performance boost.
[UIView animateWithDuration:0.5f
animations:^{
[self.view setAlpha:1.0f];
[self.view setOpaque:YES];
}];
}
Note that the tab bar is already presenting view controllers. You should not try to present the view controllers yourself. Let the tab bar manage this for you; that's what it's for.

Resources