#pragma CATransition动画实现- (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view{//创建CATransition对象CATransition *animation = [CATransition animation];//设置运动时间animation.duration = DURATION;//设置运动typeanimation.type = type;if (subtype != nil) {//设置子类animation.subtype = subtype;}//设置运动速度animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;[view.layer addAnimation:animation forKey:@"animation"];}代码说明:
#pragma UIView实现动画- (void) animationWithView : (UIView *)view WithAnimationTransition : (UIViewAnimationTransition) transition{[UIView animateWithDuration:DURATION animations:^{[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];[UIView setAnimationTransition:transition forView:view cache:YES];}];}3.改变View的背景图,便于切换时观察
#pragma 给View添加背景图-(void)addBgImageWithImageName:(NSString *) imageName{self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:imageName]];}二.调用上面的方法实现我们想要的动画
2.下面我们就开始编写点击button要回调的方法
(1).定义枚举来标示按钮所对应的动画类型,代码如下:
typedef enum : NSUInteger {Fade = , //淡入淡出Push, //推挤Reveal, //揭开MoveIn, //覆盖Cube, //立方体SuckEffect, //吮吸OglFlip, //翻转RippleEffect, //波纹PageCurl, //翻页PageUnCurl, //反翻页CameraIrisHollowOpen, //开镜头CameraIrisHollowClose, //关镜头CurlDown, //下翻页CurlUp, //上翻页FlipFromLeft, //左翻转FlipFromRight, //右翻转} AnimationType;(2),获取Button的Tag值:
UIButton *button = sender;AnimationType animationType = button.tag;
NSString *subtypeString;switch (_subtype) {case :subtypeString = kCATransitionFromLeft;break;case :subtypeString = kCATransitionFromBottom;break;case :subtypeString = kCATransitionFromRight;break;case :subtypeString = kCATransitionFromTop;break;default:break;}_subtype += ;if (_subtype > ) {_subtype = ;}(4),通过switch结合上边的枚举来判断是那个按钮点击的
switch (animationType){//各种Case,此处代码下面会给出 }3.调用我们封装的运动方法,来实现动画效果
case Fade:[self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];break;(2).Push效果
case Push:[self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];break;
(3).揭开效果:
case Reveal:[self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];break;效果图如下:
(4).覆盖效果
case MoveIn:[self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];break;
(5).立方体效果
case Cube:[self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];break;效果如下:
(6).吮吸效果
case SuckEffect:[self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];break;效果如下:
(7).翻转效果
case OglFlip:[self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];break;效果图如下:
8.波纹效果
case RippleEffect:[self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];break;
(9).翻页和反翻页效果
case PageCurl:[self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];break;case PageUnCurl:[self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];break;
(10).相机打开效果
case CameraIrisHollowOpen:[self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];break;case CameraIrisHollowClose:[self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];break;
(11),调用上面封装的第二个动画方法
case CurlDown:[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];break;case CurlUp:[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];break;case FlipFromLeft:[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];break;case FlipFromRight:[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];break;以上内容是针对iOS开发中常用的各种动画、页面切面效果的相关介绍,希望对大家有所帮助!