先是用xib拖的一个界面,用代码让各个视图动起来就制作成一个简单好看的动画效果了。
最终的动画效果:
.h文件
#import <UIKit/UIKit.h>
@interface FirstAnimationViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *blackBackGround;
@property (strong, nonatomic) IBOutlet UIImageView *shineImageView;
@property (strong, nonatomic) IBOutlet UIImageView *shipImageView;
@property (strong, nonatomic) IBOutlet UIImageView *grayCloud1;
@property (strong, nonatomic) IBOutlet UIImageView *grayCloud2;
@property (strong, nonatomic) IBOutlet UIImageView *blueCloud;
@property (strong, nonatomic) IBOutlet UIImageView *whiteCloud1;
@property (strong, nonatomic) IBOutlet UIImageView *whiteCloud2;
.m文件
// FirstAnimationViewController.m
// try_firstAnimation
//
// Created by Bear on 15/4/23.
// Copyright (c) 2015年 Bear. All rights reserved.
//
#import "FirstAnimationViewController.h"
@interface FirstAnimationViewController ()
@end
@implementation FirstAnimationViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
_shineImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self cloudAniamtion];
[self whiteCloudAnimation];
[self shipAniamtion];
[self sunShineAnimation];
[self disappearAnimation];
}
/*-------- 光照效果动画 --------*/
- (void)sunShineAnimation
{
_shineImageView.frame = CGRectMake(370, -5, CGRectGetWidth(_shineImageView.frame), CGRectGetHeight(_shineImageView.frame));
_shineImageView.layer.anchorPoint = CGPointMake(1, 0);//设置锚点到光照图片的右上角,使它从右上角开始放大
CAAnimationGroup * animationGroup = [CAAnimationGroup animation];
animationGroup.removedOnCompletion = NO;
animationGroup.fillMode = kCAFillModeForwards;//设置为动画完成后的状态
animationGroup.duration = 1.5;
animationGroup.repeatCount = 1;
animationGroup.timingFunction = UIViewAnimationCurveEaseInOut;
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.xy"];
scaleAnimation.fromValue = @0.1;//开始的大小
scaleAnimation.toValue = @1.0;//最后的大小
scaleAnimation.duration = 1.5;
CAKeyframeAnimation *opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.duration = 1.5;
opacityAnimation.removedOnCompletion = NO;
animationGroup.animations = @[scaleAnimation, opacityAnimation];
[_shineImageView.layer addAnimation:animationGroup forKey:@"pulse"];
}
/*--------- 船动画 ----------*/
- (void)shipAniamtion
{
[UIView animateWithDuration:1.6 animations:^{
_shipImageView.transform = CGAffineTransformMakeTranslation(190, 0);
}];
}
/*----------- 云朵动画 --------------*/
//乌云动画
- (void)cloudAniamtion
{
[UIView animateWithDuration:1.4 animations:^{
_grayCloud1.transform = CGAffineTransformMakeTranslation(-286, 0);
_grayCloud1.alpha = 0.5;
_grayCloud2.transform = CGAffineTransformMakeTranslation(286, 0);
_grayCloud2.alpha = 0.5;
}];
}
//白云动画
- (void)whiteCloudAnimation
{
[UIView animateWithDuration:1.2 animations:^{
_blueCloud.alpha = 1;
_blueCloud.transform = CGAffineTransformMakeTranslation(248, 0);
_whiteCloud1.alpha = 1;
_whiteCloud1.transform = CGAffineTransformMakeTranslation(-143, 0);
_whiteCloud2.alpha = 1;
_whiteCloud2.transform = CGAffineTransformMakeTranslation(-55, 0);
}];
}
//背景消失动画
- (void)disappearAnimation
{
[UIView animateWithDuration:1.5 animations:^{
_blackBackGround.alpha = 0.2;
}];
}
@end