实现类似地球转动的效果

看到微信的启动图,联想到了怎样让地球转动起来这个动效,随后自己就亲身实现了一下,效果如下:

动图.gif
动图.gif

具体实现代码请参考:
https://github.com/Mortime/MM_EarthRotationAnimation.git
核心代码如下:

  1. 实现圆环的动态运转
    #pragma mark -- 实现旋转
    -(void)rotationpAnimationImageView:(UIImageView *)image{
    CABasicAnimation *animation = [ CABasicAnimation
    animationWithKeyPath: @"transform" ];
    // 设置类型
    animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    // 让旋转围绕Z轴
    animation.toValue = [ NSValue valueWithCATransform3D:
    CATransform3DMakeRotation(M_PI , 0.0, 0.0, 1.0) ];
    animation.duration = 5;
    animation.cumulative = YES;
    animation.repeatCount = MAXFLOAT;
    // 添加一个像素的透明图片,去除边缘锯齿
    CGRect imageRrect = CGRectMake(0, 0,imageView.frame.size.width, imageView.frame.size.height);
    UIGraphicsBeginImageContext(imageRrect.size);
    [imageView.image drawInRect:CGRectMake(1,1,imageView.frame.size.width-2,imageView.frame.size.height-2)];
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [imageView.layer addAnimation:animation forKey:nil];
    }
  2. 实现效果图中小人的动态跑步
    - (void)animationImageView:(NSString *)imageName count:(NSInteger)count{
    // 判断动画是否在执行
    if ([imgView isAnimating]) return;
    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 0; i < count; i++) {
    NSString *imageName = [NSString stringWithFormat:@"%@%d.png", name, i+1];
    // 设置全路径
    NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    [arrayM addObject:image];
    }
    // 设置动画数据
    imgView.animationImages = arrayM;
    imgView.animationRepeatCount = 0;
    imgView.animationDuration = imgView.animationImages.count * 0.05;
    // 动画开始
    [imgView startAnimating];
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,141评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,572评论 6 30
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 1,424评论 0 3
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 838评论 0 0
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 1,144评论 1 6