SahaNerede
SahaNerede

Reputation: 219

objective-c CATransition issue

that code blocks for storyboard viewcontrollers animation and its working but not what i want.. iwant left to right animation bu its doing "left bottom" corner to top right corner. not left to right why?

and second how can i stop animation?

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

CATransition* transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;



[destinationController.view.layer addAnimation:transition forKey:kCATransition];
[sourceViewController presentViewController:destinationController animated:YES completion:nil];

Upvotes: 0

Views: 791

Answers (2)

Sulthan
Sulthan

Reputation: 130172

  1. You need to wrap the code in a CATransaction.
  2. You need to turn off the default animation (animated:NO)
  3. For the animation to have effect, it must be added to the superview's layer. In case of presented controllers, the window layer would be a smart choice.
  4. "Move In" animation "from Right" won't be a "left to right" animation.
  5. Note that it most cases you have to modify the animation direction depending on current interface orientation.

Sidenote: changing the animation of modal controllers is "frowned upon". You will simplify the problem greatly if you just use a child view controller.

Upvotes: 1

Andrew
Andrew

Reputation: 15377

I believe the "left to right" animation you are looking for may be the push animation of a UINavigationController. This may also be achievable with the kCATransitionPush transition type. Also, presentViewController triggers a "modal" animation (from bottom), so maybe using NO for the animated parameter in presentViewController might help also if you are not using a UINavigationController.

Upvotes: 0

Related Questions