0

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!

Lucas Eduardo
  • 11,217
  • 5
  • 43
  • 49
Frostrar
  • 337
  • 6
  • 18

4 Answers4

2

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

iAhmed
  • 6,168
  • 2
  • 24
  • 31
2

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.

nanothread
  • 910
  • 1
  • 10
  • 25
0

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.

Calin Chitu
  • 1,099
  • 7
  • 13
  • Thanks for your answer.When you say "by ctrl+drag from you button to the .m file" does mean drag from the button to the "View controller" icon underneath the view? Because i cant drag to the .m file in the navigator. Also when i try to add the dismiss line provided in my original post to the .m file i get an error saying "Use of undeclared identifier self" – Frostrar Sep 09 '13 at 12:30
  • If you didn't do already, you have to create a custom subclass of UIViewController and associate it in storyboard with your viewcontroller. When you are in the storyboard, enable "show assistant editor" from editor buttons right up corner and you will see your newly created .h file. Switch to the .m file and there you can ctrl+drag your ibaction. Try on youtube, there are plenty of video tutorials for this. – Calin Chitu Sep 09 '13 at 12:37
0

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

czechboy
  • 899
  • 7
  • 15
  • Just tried this solution and it does work as it slides the view back out. However, i am building the prototype to get a feel of the flow in the app so if in the first view I tap a user to select him i use a cross dissolve transition to change the view to a screenshot of the ui where this user as been selected. I now need this view to slide down again but not back to the original view but to a next screenshot where the participants icon has now changed to indicate a participant has been selected. Hope this makes sense... – Frostrar Sep 09 '13 at 12:42
  • Well unwind segues are only good for getting back to a previous state (controller). If you need to push/show another controller (not the parent), just use a regular segue in the storyboard. If none of the predefined are good for you (Push, Modal, Popover), just select Custom. But you will have to provide a UIStoryboardSegue subclass - there's plenty of info on how to create one in the documentation. I have done that, not difficult - basically you just define what needs to happen before two points in time. So you can do an animation of any kind. – czechboy Sep 09 '13 at 13:25
  • Cool - i will definitely try that today. One question though: When i have a created my subclass of UIStoryboardSegue is this the code i need to put in the class? http://stackoverflow.com/questions/14081880/xcode-custom-segue-opposite-of-cover-vertical-top-to-bottom-complete-newbi?rq=1 – Frostrar Sep 10 '13 at 07:15
  • Yes, something like that. – czechboy Sep 12 '13 at 16:34