Reputation: 337
I am trying to use a custom segue in xcode storyboard to have a view slide back down (the reverse of cover vertical).
I have learned that i need to call:
[self dismissViewControllerAnimated:YES completion:nil];
But where and how do i do this? Should this be in the .h file? And will this then create a transition i can then choose from the drop down menu when selecting a transition?
I am new to this so think i need a step by step guide. Thanks in advance!
Upvotes: 0
Views: 2910
Reputation: 908
You don't need a custom segue for this - when you want your screen to do down (let's say when you press a button) just implement this in the view controller you want to go down.
-(IBAction)closeScreen:(id)sender{
[self dismissViewControllerAnimated:YES completion:NULL];
}
You will call this in the .m file.
Upvotes: 2
Reputation: 944
Something called unwind segue
is perfect for this. Imagine FooViewController presents BarViewController. You have both in the Storyboard. In the FooViewController.h
define a method - (IBAction)onCloseBarController:(UIStoryboardSegue *)segue;
and in the FooViewController.m
just put in an empty implementation
- (IBAction)onCloseBarController:(UIStoryboardSegue *)segue
{
}
Now, go to your Storyboard and in the BarViewController
view find the control that you want to use for triggering the close action. Click on that control, in the right side inspector go to the Triggering Segues (the rightmost option) and drag from the action
(in the case of UIBarButtonItem
) or Sent Events
(in the case of UIButton
) to the Exit control at the bottom of the BarViewController
in the Storyboard. It then should show you all unwind segues available and just select the onCloseBarController
.
Unwind segues are made specifically for this. The best part - you don't have to manually dismiss the controller, the unwind segue does that automatically. So you can just use the method onCloseBarController
as a notification method of the dismissal.
Pretty good tutorial on unwind segues: http://pragmaticstudio.com/blog/2013/2/5/unwind-segues
Upvotes: 0
Reputation: 6704
Suppose there is a back button at which you want to go previous view Controller. At button action method you have to write this line of code as follows
-(IBAction)Back{
[self dismissViewControllerAnimated:NO completion:nil];
}
For Animation write this Method in that class which you want to animate
- (void)fadeIn
{
self.view.transform = CGAffineTransformMakeScale(1.3, 1.3);
self.view.alpha = 0;
[UIView animateWithDuration:.35 animations:^{
self.view.alpha = 1.0;
self.view.transform = CGAffineTransformMakeScale(1, 1);
}];
}
call this method from ViewWillAppear Method of that class as:
-(void)viewWillAppear:(BOOL)animated{
[self fadeIn];
}
For advance Animation at check this : https://github.com/JosephLin/TransitionTest
Upvotes: 2
Reputation: 1099
You don't need a custom segue only for cover vertical transition.
It's enough if you setup a modal transition in storyboard (using ctrl+drag between your button and destination viewcontroller). Then click on the segue line and change the transition from default to cover vertical in inspector (right upper corner).
@ your destination view controller you create an ibaction from the button you want to dismiss the view (by ctrl+drag from your button to the .m file). then you add the dismiss line to this ibaction.
Upvotes: 0