Eyes, JAPAN Blog > Custom Push Segue

Custom Push Segue

will

この記事は1年以上前に書かれたもので、内容が古い可能性がありますのでご注意ください。

The Storyboard of Xcode provides fast and connivent tool to develop the views and transition.

Developer can use Segue to define the transition from one view to another. However, if we just use the predefined segue (push and modal), the direction of transition is fixed.  For instance, the PUSH will be from right to left.

Some times, we need different directions with the predefined ones. In this case, we can custom the segue.

Give the example about customing push segue to make the transition from left to right:

1. Create class “LeftToRightPushSegue”, which externs from UIStoryboardSegue

#import "LeftToRighPushSegue.h"
#import <QuartzCore/QuartzCore.h>

@implementation LeftToRighPushSegue

-(void)perform
{

UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];

UIViewController *destinationController = (UIViewController*)[self destinationViewController];

CATransition* transition = [CATransition animation];

transition.duration = .25;

transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

transition.type = kCATransitionPush;

transition.subtype = kCATransitionFromLeft;

[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];

[sourceViewController.navigationController pushViewController:destinationController animated:NO];

}

@end

2. When the view is ready to pop up from stack, the animation of transition also need to be changed, otherwise, the view will be poped up with default direction:

-(void)pushBack:(id)sender
{
//Setting the direction of popup from right to left
CATransition *transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController popViewControllerAnimated:YES];
}
  • このエントリーをはてなブックマークに追加

Comments are closed.