码迷,mamicode.com
首页 > 其他好文 > 详细

核心动画的使用 - 引导页动画

时间:2019-02-18 23:10:21      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:获取   mamicode   imp   nat   src   name   with   str   uid   

1、引导页动画

  • 1.1 ViewController.m

    @interface ViewController () <UIScrollViewDelegate>
    
    @property (weak, nonatomic) IBOutlet UIImageView *sunView;
    @property (weak, nonatomic) IBOutlet UIImageView *personView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        UIImage *bgImage = [UIImage imageNamed:@"520_userguid_bg"];
    
        // ScrollView
        UIScrollView *scorollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        scorollView.contentSize = bgImage.size;
        scorollView.delegate = self;
        scorollView.decelerationRate = 0.5;
        [self.view insertSubview:scorollView atIndex:0];
    
        // bg
        UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
        CGRect rect = bgImageView.frame;
        rect.size.height = self.view.bounds.size.height;
        bgImageView.frame = rect;
        [scorollView addSubview:bgImageView];
    
        // cg
        UIImage *cgImage = [UIImage imageNamed:@"520_userguid_cg"];
        UIImageView *cgImageView = [[UIImageView alloc] initWithImage:cgImage];
        rect = cgImageView.frame;
        rect.size.height = self.view.bounds.size.height;
        cgImageView.frame = rect;
        [bgImageView addSubview:cgImageView];
    
        // fg
        UIImage *fgImage = [UIImage imageNamed:@"520_userguid_fg"];
        UIImageView *fgImageView = [[UIImageView alloc] initWithImage:fgImage];
        rect = cgImageView.frame;
        rect.size.height = self.view.bounds.size.height;
        fgImageView.frame = rect;
        [bgImageView addSubview:fgImageView];
    
        // cloud
        UIImage *cloudImage = [UIImage imageNamed:@"520_userguid_cloud"];
        UIImageView *cloudImageView = [[UIImageView alloc] initWithImage:cloudImage];
        [bgImageView addSubview:cloudImageView];
    }
    
    // 只要一滚动就会调用
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
        // 获取 scrollView 偏移量
        CGFloat offsetX = scrollView.contentOffset.x;
    
        int intOffsetX = (int)offsetX;
    
        // 切换人物的图片
        NSString *imageName = [NSString stringWithFormat:@"520_userguid_person_taitou_%d", (intOffsetX % 2 + 1)];
        self.personView.image = [UIImage imageNamed:imageName];
    
        // 旋转小太阳
        self.sunView.transform = CGAffineTransformRotate(self.sunView.transform, 5 / 180.0 * M_PI);
    }
    
    @end
  • 1.2 效果

  • 技术图片 ------ 技术图片

核心动画的使用 - 引导页动画

标签:获取   mamicode   imp   nat   src   name   with   str   uid   

原文地址:https://www.cnblogs.com/CH520/p/9483618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!