本篇文章主要介绍了iOS 实现简单的加载等待动画示例(思路与实现),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
先看下最后基本要实现的效果
2.然后就是在XDColorCircle里面代码思路 3.思路捋顺代码就很方便 创建圈圈所在的View 创建渐变图层并添加到圈圈视图 添加mask属性只让图层只显示一个圈圈 让圈圈转起来添加动画 添加中间的大文字Label 4.然后在controller里面使用 只是个简单的动画实现小例子,可以看出活用CAShapeLayer和CABasicAnimation可以做出更炫的动画效果 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
//创建XDColorCircle的实例化对象
XDColorCircle *circle=[[XDColorCircle alloc]initWithFrame:CGRectMake(0 ,100,self.view.frame.size.width,200)];
//添加到视图上展示
[self.view addSubview:circle];
//先都写在这个构造方法里面吧
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
self.backgroundColor=[UIColor clearColor];
UIView *circleView=[[UIView alloc]init];
circleView.frame=CGRectMake(0, 0,frame.size.width,frame.size.height);
circleView.backgroundColor=[UIColor blueColor];
[self addSubview: circleView];
CAGradientLayer * gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)[UIColor whiteColor].CGColor,(__bridge id)[UIColor cyanColor].CGColor];
gradientLayer.locations = @[@0.2,@1.0];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame =CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[circleView.layer insertSublayer:_gradientLayer atIndex:0];
CAShapeLayer *layer=[[CAShapeLayer alloc]init];
CGMutablePathRef pathRef=CGPathCreateMutable();
CGPathAddRelativeArc(pathRef, nil,frame.size.width/2.0,frame.size.height/2.0,frame.size.width<frame.size.height?frame.size.width/2.0-5:frame.size.height/2.0-5,0, 2*M_PI);
layer.path=pathRef;
layer.lineWidth=5;
layer.fillColor=[UIColor clearColor].CGColor;
layer.strokeColor=[UIColor blackColor].CGColor;
CGPathRelease(pathRef);
circleView.layer.mask=layer;
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; ;
// 设定动画选项
animation.duration = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.repeatCount =HUGE_VALF;
// 设定旋转角度
animation.fromValue = [NSNumber numberWithFloat:0.0]; // 起始角度
animation.toValue = [NSNumber numberWithFloat:2 * M_PI]; // 终止角度
[circleView.layer addAnimation:animation forKey:@"rotate-layer"];
UILabel *label=[[UILabel alloc]init];
label.text=@"测试中";
label.font=[UIFont systemFontOfSize:32];
label.textAlignment=NSTextAlignmentCenter;
label.frame=CGRectMake(0, 0,frame.size.width,frame.size.height);
label.backgroundColor=[UIColor clearColor];
[self addSubview:label];
//创建XDColorCircle的实例化对象
XDColorCircle *circle=[[XDColorCircle alloc]initWithFrame:CGRectMake(0 ,100,self.view.frame.size.width,200)];
//添加到视图上展示
[self.view addSubview:circle];
本文标题为:iOS 实现简单的加载等待动画示例(思路与实现)


- 详解flutter engine 那些没被释放的东西 2022-12-04
- Android实现监听音量的变化 2023-03-30
- Android studio实现动态背景页面 2023-05-23
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- Flutter实现底部和顶部导航栏 2022-08-31
- iOS 对当前webView进行截屏的方法 2023-03-01
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- Android实现轮询的三种方式 2023-02-17
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14