OC(二)-加载动画 - 图1
    .h

    1. //
    2. // gifView.h
    3. // GifPicture
    4. //
    5. // Created by HMC on 16/8/23.
    6. // Copyright © 2016年 SKing. All rights reserved.
    7. //
    8. #import <UIKit/UIKit.h>
    9. @interface gifView : UIView
    10. //外圈
    11. @property (weak, nonatomic) IBOutlet UIImageView *cycle;
    12. // logo 图标
    13. @property (weak, nonatomic) IBOutlet UIImageView *logo;
    14. //显示的message
    15. @property (weak, nonatomic) IBOutlet UILabel *messageLabel;
    16. + (instancetype)initInstance;
    17. /**
    18. * 动画
    19. *
    20. * @param message 加载的文字
    21. * @param isCycleAnimation 圆是否有动画
    22. * @param isLogoAnimation logo 是否有动画
    23. */
    24. -(void)startAnimationWithMessage:(NSString *) message isCycleAnimation:(BOOL) isCycleAnimation isLogoAnimation:(BOOL)isLogoAnimation;
    25. @end

    .m

    1. //
    2. // gifView.m
    3. // GifPicture
    4. //
    5. // Created by HMC on 16/8/23.
    6. // Copyright © 2016年 SKing. All rights reserved.
    7. //
    8. #import "gifView.h"
    9. @implementation gifView
    10. + (instancetype)initInstance {
    11. return [[[NSBundle mainBundle] loadNibNamed:@"gifView" owner:nil options:nil] lastObject];
    12. }
    13. -(void)startAnimationWithMessage:(NSString *) message isCycleAnimation:(BOOL) isCycleAnimation isLogoAnimation:(BOOL)isLogoAnimation {
    14. if(message != nil ){
    15. self.messageLabel.text = message;
    16. }
    17. if(isCycleAnimation){
    18. CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    19. rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    20. rotationAnimation.duration = 1.5;
    21. rotationAnimation.cumulative = YES;
    22. rotationAnimation.repeatCount = MAXFLOAT;
    23. // 切换后台再回来动画不停止
    24. rotationAnimation.removedOnCompletion = NO;
    25. [self.cycle.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    26. }
    27. if(isLogoAnimation){
    28. CABasicAnimation * transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    29. transformAnimation.removedOnCompletion = NO;
    30. transformAnimation.duration = 3.0;
    31. transformAnimation.toValue = @(0);
    32. transformAnimation.fromValue = @(M_PI);
    33. transformAnimation.repeatCount = MAXFLOAT;
    34. [self.logo.layer addAnimation:transformAnimation forKey:@"transformAnimation"];
    35. CABasicAnimation * transformAnimation1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    36. transformAnimation1.removedOnCompletion = NO;
    37. transformAnimation1.duration = 3.0;
    38. transformAnimation1.fromValue = @(-M_PI);
    39. transformAnimation1.toValue = @(0);
    40. transformAnimation1.repeatCount = MAXFLOAT;
    41. [self.logo.layer addAnimation:transformAnimation1 forKey:@"transformAnimation1"];
    42. }
    43. }
    44. @end

    调用

    1. //
    2. // ViewController.m
    3. // GifPicture
    4. //
    5. // Created by HMC on 16/8/23.
    6. // Copyright © 2016年 SKing. All rights reserved.
    7. //
    8. #import "ViewController.h"
    9. #import "gifView.h"
    10. @interface ViewController ()
    11. @end
    12. @implementation ViewController
    13. - (void)viewDidLoad {
    14. [super viewDidLoad];
    15. gifView * animateView = [gifView initInstance];
    16. animateView.center = self.view.center;
    17. [animateView startAnimationWithMessage:@"跟我一起转圈圈,哈哈" isCycleAnimation:YES isLogoAnimation:YES];
    18. [self.view addSubview:animateView];
    19. }
    20. @end

    代码地址: 点这里