I have a custom storyboard segue animation but its not coming out the way I want it to. Instead of "wiping" in over the view controller, I want it to "push" away the current view controller with the new one next to it. (not like the push segue, more like the the effect seen in the photos app when you swipe through photos). Any ideas? Thanks.

- (void)perform {

UIViewController *currentViewController = self.sourceViewController;
UIViewController *newViewController = self.destinationViewController;


[currentViewController.view addSubview:newViewController.view];


newViewController.view.transform = CGAffineTransformMakeScale(0.05, 0.05);


CGPoint originalCenter = newViewController.view.center;

newViewController.view.center = self.originatingPoint;

[UIView animateWithDuration:1.9
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{

                     newViewController.view.transform = CGAffineTransformMakeScale(1.0, 100.0);
                     newViewController.view.center = originalCenter;
                 }
                 completion:^(BOOL finished){
                     [newViewController.view removeFromSuperview]; // remove from temp super view
                     [currentViewController presentViewController:newViewController animated:NO completion:NULL]; // present VC
                 }];
}

有帮助吗?

解决方案

animations:^{
    newViewController.view.transform = CGAffineTransformMakeScale(1.0, 100.0);
    newViewController.view.center = originalCenter;
}

It looks like you're not animating the current view controller's view. I'm also not sure why you're setting the transform of your new view controller's view. I'd expect your code to look something like this:

CGPoint originalCenter = currentViewController.view.center;
CGPoint newCurrentVCCenter = CGPointMake(currentViewController.view.center.x - screenWidth, currentViewController.center.y);
[UIView animateWithDuration:1.9
                  delay:0.0
                options:UIViewAnimationOptionCurveEaseInOut
animations:^{
    currentViewController.center = newCurrentVCCenter;
    newViewController.view.center = originalCenter;
}
completion:^(BOOL finished){
     // clean up here
}];

In other words, you're moving currentViewController.view and newViewController.view, so that the current view and new view both shift left the same amount and at the same time.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top