- (void)demoAnimationGroup { static NSString * const kCAPostionKeyPath = @"position"; static NSString * const kCAOpacityKeyPath = @"opacity"; static NSString * const kCARotationKeyPath = @"transform.rotation"; static NSString * const kCAScaleKeyPath = @"transform.scale"; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:_demoView.layer.position]; [path addCurveToPoint:CGPointMake(260, 400) controlPoint1:CGPointMake(0, 460) controlPoint2:CGPointMake(320, 0)]; //路径动画 CAKeyframeAnimation *posAnimation = [CAKeyframeAnimation animationWithKeyPath:kCAPostionKeyPath]; posAnimation.path = path.CGPath; posAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; //透明度动画 CABasicAnimation *opaAnimation = [CABasicAnimation animationWithKeyPath:kCAOpacityKeyPath]; opaAnimation.duration = 2.0f; opaAnimation.toValue = @(0.3f); opaAnimation.autoreverses = YES; //旋转动画 CABasicAnimation *rotAnimation = [CABasicAnimation animationWithKeyPath:kCARotationKeyPath]; rotAnimation.duration = 2.0f; rotAnimation.toValue = @(M_PI); rotAnimation.autoreverses = YES; //缩放动画 CABasicAnimation *scaAnmaiton = [CABasicAnimation animationWithKeyPath:kCAScaleKeyPath]; scaAnmaiton.duration = 2.0f; scaAnmaiton.toValue = @(1.5f); scaAnmaiton.autoreverses = YES; //设置动画组 CAAnimationGroup *group = [CAAnimationGroup animation]; group.animations = @[posAnimation, opaAnimation, rotAnimation, scaAnmaiton]; group.duration = 4.0f; group.removedOnCompletion = NO; group.fillMode = kCAFillModeForwards; [_demoView.layer addAnimation:group forKey:nil]; }
- (void)viewTransition { static NSString * const kCATransitionTypeFlip = @"oglFlip"; //翻页效果 CATransition *transition = [CATransition animation]; transition.type = kCATransitionTypeFlip; transition.subtype = kCATransitionFromRight; transition.duration = 1.5f; [_transitionOrangeView.layer addAnimation:transition forKey:nil]; [self.view performSelector:@selector(sendSubviewToBack:) withObject:_transitionOrangeView afterDelay:1.0f]; }
- (void)anotherTransition { _transitionBlueView = [[UIView alloc] initWithFrame:self.view.bounds]; _transitionBlueView.backgroundColor = [UIColor blueColor]; [UIView transitionFromView:_transitionOrangeView toView:_transitionBlueView duration:1.0f options:UIViewAnimationOptionTransitionCrossDissolve completion:nil]; }