iosxcodeanimationcatransition

iOS 8 CATransition - slide view off screen


I'm trying to slide a view onto the screen, and slide it off the screen when the user hits the cancel button. The sliding onto the screen is working great, with the following code.

CATransition *trans = [CATransition animation];
trans.duration = 0.2;
trans.type = kCATransitionMoveIn;
trans.subtype = kCATransitionFromLeft;

[viewToAnimate.layer addAnimation:trans forKey:nil];

[self.view addSubView:viewToAnimate];

However, I am having trouble figuring out the best way to have it animate off of the screen through CATransition (or other means). How is this accomplished?

I'm sure its something small, but the other questions I looked at didn't seem to cut it. Thanks in advance for any assistance.


Solution

  • Try this, it actually changes the y position of the screen to the end of screen, and creates the same animation like the one you tried.

    CGRect temp = self.view.frame;
    temp.origin.x = [[UIScreen mainScreen] bounds].size.width ;
    [UIView animateWithDuration:0.5
                          delay:0.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{
                         self.view.frame = temp;
                     }completion:^(BOOL finished){
                         [self.view removeFromSuperview];
                     }];