Reputation: 7474
My application is displaying Arabic text in which i want push animation from left side and not from right side which ios provides by default.
I am using storyboards.I have created custom segue.
I have gone through all options cocoacontrols but have not found desired one.
I have found several options as follows:
1) CATransition
2) Animation
3) maintaining view controllers array - which creates lot of mess
Below code gives perfect effect but black patches as show below are not acceptable -
-(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; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[sourceViewController.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
[destinationController.view setBackgroundColor:[UIColor whiteColor]];
}
Implemented below code give no black patches - but not desired animation
-(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:CGAffineTransformMakeScale(0.5,0.5)];
[destinationViewController.view setAlpha:1.0];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
[destinationViewController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)];
[destinationViewController.view setAlpha:1.0];
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview];
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}];
}
By changing above code - but i am not getting desired result
-(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 setAlpha:1.0];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
sourceViewController.view.frame = CGRectMake(sourceViewController.view.frame.size.width*2, 0, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);
}
completion:^(BOOL finished){
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}];
}
Upvotes: 1
Views: 909
Reputation: 315
This is a custom segue in swift that uses the messy way, manipulates list of view controllers.. Anyway, I wanted to push to a view controller, but make it look like it was a pop, and I tried to do it with all sorts of animations, but in the end - for me, this was the most simplest way to get what I wanted as I don't have to maintain my code, if iOS styling changes and so on, as it uses general pop - it should remain the same as default pop in the system.. Anyway, to the code:
class ReversePushSegue : UIStoryboardSegue {
override func perform() {
let sourceViewController = self.sourceViewController as UIViewController
let destinationViewController = self.destinationViewController as UIViewController
var vcs : NSMutableArray = NSMutableArray(array: sourceViewController.navigationController.viewControllers)
vcs.insertObject(destinationViewController, atIndex: vcs.count - 1)
sourceViewController.navigationController.viewControllers = vcs
sourceViewController.navigationController.popViewControllerAnimated(true)
}
}
What it does - it adds destinationViewController to the list as second last and then pops to it..
Upvotes: 0
Reputation: 108
use below code In appDelegate.m - applicationDidFinishLaunchingWithOptions
self.window.backgroundColor = [UIColor whitecolor];
Upvotes: 1