核心动画的使用 - 活动指示器

1、活动指示器

  • 1.1 创建活动指示器

    @property (nonatomic, strong) UIView *activityIndicatorView;
    
    self.activityIndicatorView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    self.activityIndicatorView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.activityIndicatorView];
    
    // 创建复制图层
    CAReplicatorLayer *repLayer = [CAReplicatorLayer layer];                    // 可以把图层里面所有子层复制
    repLayer.frame = self.activityIndicatorView.bounds;
    [self.activityIndicatorView.layer addSublayer:repLayer];
    
    // 创建指示器图层
    CALayer *layer = [CALayer layer];
    layer.transform = CATransform3DMakeScale(0, 0, 0);
    layer.position = CGPointMake(self.activityIndicatorView.bounds.size.width / 2, 20);
    layer.bounds = CGRectMake(0, 0, 10, 10);
    layer.backgroundColor = [UIColor greenColor].CGColor;
    [repLayer addSublayer:layer];
    
    // 设置缩放动画
    CGFloat duration = 1.0;
    CABasicAnimation *anim = [CABasicAnimation animation];
    anim.keyPath = @"transform.scale";
    anim.fromValue = @1;
    anim.toValue = @0;
    anim.duration = duration;
    anim.repeatCount = MAXFLOAT;
    [layer addAnimation:anim forKey:nil];
    
    // 设置复制层中子层
    CGFloat count = 20;
    CGFloat angle = M_PI * 2 / count;
    repLayer.instanceCount = count;                                             // 设置复制层里面有多少个子层,包括原始层
    repLayer.instanceTransform = CATransform3DMakeRotation(angle, 0, 0, 1);     // 设置复制子层偏移量,不包括原始层,相对于原始层 x 偏移
    repLayer.instanceDelay = duration / count;                                  // 设置复制层动画延迟时间
  • 1.2 效果

    1213778-20180815123919902-261249806.gif

转载于:https://www.cnblogs.com/CH520/p/9480746.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是可以实现利用滚动视图实现效果很不错的用户指引界面功能。支持引导页面的自动滑动和手动滑动。两个页面之间的过渡是渐隐渐现(淡入淡出 fade in and fade out)的动画效果。指引页面的文字有固定文字标题和随着页面切换而切换的文字标题。这种用户指引界面用在Path 3.0 App中。由于用了auto layout,所以只支持iOS 6.0 以上。若在iOS 5.0或以下运行,页面切换会有跳动的感觉。 使用方法: 设置每个页面的图片以及相应的文字: // Init the pages texts, and pictures. ICETutorialPage *layer1 = [[ICETutorialPage alloc] initWithSubTitle:@"Picture 1" description:@"Champs-Elysées by night" pictureName:@"tutorial_background_00@2x.jpg"]; ICETutorialPage *layer2 = [[ICETutorialPage alloc] initWithSubTitle:@"Picture 2" description:@"The Eiffel Tower with cloudy weather" pictureName:@"tutorial_background_01@2x.jpg"]; [...] // Load into an array. NSArray *tutorialLayers = @[layer1,layer2,layer3,layer4,layer5]; 加载指引页面: self.viewController = [[ICETutorialController alloc] initWithNibName:@"ICETutorialController_iPhone" bundle:nil andPages:tutorialLayers]; // Set the common styles, and start scrolling (auto scroll, and looping enabled by default) [self.viewController setCommonPageSubTitleStyle:subStyle]; [self.viewController setCommonPageDescriptionStyle:descStyle]; // Set button 1 action. [self.viewController setButton1Block:^(UIButton *button){ NSLog(@"Button 1 pressed."); }]; // Set button 2 action, stop the scrolling. __unsafe_unretained typeof(self) weakSelf = self; [self.viewController setButton2Block:^(UIButton *button){ NSLog(@"Button 2 pressed."); NSLog(@"Auto-scrolling stopped."); [weakSelf.viewController stopScrolling]; }]; // Run it. [self.viewController star

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值