Storyboard Segues/animating source AND destination simultaneously

Discussion in 'iOS Programming' started by 16Beat, Feb 19, 2013.

  1. 16Beat macrumors newbie

    Joined:
    Feb 19, 2013
    #1
    Hi,

    i'm new to iOS-programming and have a comprehension question regarding storyboard segues in iOS-Apps.

    In many apps transitions are triggered by a swipe gesture whereby the following content slides in from right to left while pushing out the actual content to the left. You can see this effect when you start at the homescreen on your iPad and swipe left to go to the second screen with apps. The second screen with apps slides in from the right and the home screen simultaneously slides out to the left. It looks like the second screen is pushing away the first screen.

    For example, a landscape-only-app has a quiz with 10 questions - each of them appearing on a different screen. Each screen could be presented by a scene(viewcontroller) and with a modal segue you can easily present the next question by swiping left. But i only can find 4 different transition styles in interface builder and the desired effect is not in the list. Also i can not customize the transition style, like how long it will take to complete the transition(duration of the animation).

    Apple talks about subclassing UIStoryboardSegue to perform a custom segue. In general no problem, but for me it seems to be difficult to animate both viewcontroller(SourceViewController and DestinationViewController) at the same time in the described way:

    Code:
    -(void)perform {
        UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
        UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
        [sourceViewController.view addSubview:destinationViewController.view];
        [destinationViewController.view setFrame:sourceViewController.view.window.frame];
        [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(sourceViewController.view.frame.size.height, 0)];
        [UIView animateWithDuration:1
                              delay:0.0
                            options:(UIViewAnimationOptionCurveLinear)
                         animations:^{
                          // [sourceViewController.view setTransform:CGAffineTransformMakeTranslation(-sourceViewController.view.frame.size.height, 0)];
                             [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
                         }
                         completion:^(BOOL finished){
                             [destinationViewController.view removeFromSuperview];
                             [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                         }];
    }
    This is what i have tried so far - this code in my landscape-only-app just covers the source with the destination, the source does not move. My attempts to transform the x-axis of the sourceViewController allways result in a rotation of the whole animated slide. I think i can not animate a viewcontroller the same way i animate a view. But even when the sourceViewController would move to the left at the same time, i think i would have the problem that this move would result in a black hole at the right side while the source slides to the left, because the destination seems to be only an animated subview of the source.

    Did i miss something and it is rather easy to achive the desired effect?
    Or is it an unwished hack to animate the transition between two viewcontrollers this way and i should use only one viewcontroller for the whole quiz and create a tagged subview for each card, which i should animate from within one viewcontroller?
    This would be another approach to solve my problem, but would make nonsense of the Storyboard Scenes, which help to keep the app clearly arranged within interface builder.
    Does Apple have a point of view how we should use viewcontroller versus views to create apps with such custom segues between the scenes?

    Best regards,
    16Beat
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    They don't use storyboards. They use a single scrollview with paging turned on.
     
  3. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #3
    You may also look at the UIPageControl element
     

Share This Page