Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios segues without navigationcontrollers

I would like to use storyboards for creating my app. I can find a lot of information about how to use it with the navigation- or tabcontroller but I don't wan't either of them.

My goal is to create an app which has different views but without using a navigation or tabcontroller. How do I do it?

like image 909
wvp Avatar asked Sep 05 '12 09:09

wvp


2 Answers

In IOS storyboard, if you don't want to use navigation, then you cannot use push segue. Then, you can use modal segue or custom segue. In modal segue, there are four transitions:

  1. Cover Vertical
  2. Flip Horizontal
  3. Cross Dissolve
  4. Partial Curl

However, all of these pre-defined segue animations can not preform horizontal sliding animation segue. If you want to use horizontal sliding effect, you have to use custom segue. You need to override the function like this:

- (void) perform
{
UIViewController *desViewController = (UIViewController *)self.destinationViewController;

UIView *srcView = [(UIViewController *)self.sourceViewController view];
UIView *desView = [desViewController view];

desView.transform = srcView.transform;
desView.bounds = srcView.bounds;

if(isLandscapeOrientation)
{
    if(isDismiss)
    {
        desView.center = CGPointMake(srcView.center.x, srcView.center.y  - srcView.frame.size.height);
    }
    else
    {
        desView.center = CGPointMake(srcView.center.x, srcView.center.y  + srcView.frame.size.height);
    }
}
else
{
    if(isDismiss)
    {
        desView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
    }
    else
    {
        desView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
    }
}


UIWindow *mainWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
[mainWindow addSubview:desView];

// slide newView over oldView, then remove oldView
[UIView animateWithDuration:0.3
                 animations:^{
                     desView.center = CGPointMake(srcView.center.x, srcView.center.y);

                     if(isLandscapeOrientation)
                     {
                         if(isDismiss)
                         {
                             srcView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
                         }
                         else
                         {
                             srcView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
                         }
                     }
                     else
                     {
                         if(isDismiss)
                         {
                             srcView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
                         }
                         else
                         {
                             srcView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
                         }
                     }
                 }
                 completion:^(BOOL finished){
                     //[desView removeFromSuperview];
                     [self.sourceViewController presentModalViewController:desViewController animated:NO];
                 }];
}

If you still have problem, you can check this post. It also has a youtube video to show you how to implement this custom segue:

Create Push Segue Animation Without UINavigation Controller

like image 174
James Avatar answered Nov 15 '22 07:11

James


Why don't you want them? That seems like you're making work for yourself.

You can have a navigation controller that has no visible UI, it's just responsible for pushing and popping other UIViewControllers and then the default push segue type will just work.

However, if you really don't want them you can always make a custom segue class and use that to manage you view controller stack.

like image 20
deanWombourne Avatar answered Nov 15 '22 08:11

deanWombourne