Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView animation curve not working easeinout

I am stumped by a very simple task, I want a UIView animation to do ease in / ease out but it is always linear despite using the correct animationOption.

Here is the code which by all accounts should work, it's set in a UIViewControllerAnimatedTransitioning class but I have the same issue in a previous custom segue class;

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) {

        self.dimView.alpha = 1.0;
        self.imageView.frame = self.destinationRect;

    } completion:^(BOOL finished) {

        [self.imageView removeFromSuperview];
        [self.dimView removeFromSuperview];

        [transitionContext completeTransition:YES];

     }];

However, a spring animation with the following code works although I'd rather not do this.

[UIView animateWithDuration:0.8f delay:0 usingSpringWithDamping:0.7f initialSpringVelocity:2.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) {

        self.dimView.alpha = 1.0;
        self.imageView.frame = self.destinationRect;

     } completion:^(BOOL finished){

        [self.imageView removeFromSuperview];
        [self.dimView removeFromSuperview];

        [transitionContext completeTransition:YES];

     }];

I'm getting the same behaviour on the simulator and on an iPad2 test device. Am I doing something wrong? Are there issues with animating either frame or alpha values?

like image 794
Daniel Nordh Avatar asked Sep 27 '13 13:09

Daniel Nordh


Video Answer


2 Answers

You can use the following :

[self transition:left]; //Call as required

enum animationFrom {
    top,
    bottom,
    left,
    right
};

- (void)transition:(NSUInteger)index {
    CATransition *tr=[CATransition  animation];
    tr.duration=0.45;
    tr.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    tr.type=kCATransitionPush;
    tr.delegate=self;
    switch (index) {
        case top:
            tr.subtype=kCATransitionFromBottom;
            break;
        case bottom:
            tr.subtype=kCATransitionFromTop;
            break;
        case left:
            tr.subtype=kCATransitionFromRight;
            break;
        case right:
            tr.subtype=kCATransitionFromLeft;
            break;
        default:
            break;
    }
    [self.view.layer addAnimation:tr forKey:nil];
}
like image 33
itechnician Avatar answered Oct 03 '22 06:10

itechnician


You could try this instead.-

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop)];

self.dimView.alpha = 1.0;
self.imageView.frame = self.destinationRect;

[UIView commitAnimations];

- (void) animationDidStop {
    [self.imageView removeFromSuperview];
    [self.dimView removeFromSuperview];
    [transitionContext completeTransition:YES];
}

Hope it helps.

like image 144
ssantos Avatar answered Oct 03 '22 07:10

ssantos