星空网 > 软件开发 > 操作系统

iOS大转盘抽奖

功能

点击大转盘旋转后固定到某个自己可以确定的位置

结构

转盘,开始按钮,指针

技术

CADisplayLink不停重绘,CGAffineTransform旋转,简单数学公式

核心代码

1.使用CADisplayLink不停重绘旋转底盘

// 开始转动(一直不停的转动)- (void)startRotate{    CADisplayLink* link = [CADisplayLink displayLinkWithTarget:self selector:@selector(Rotate)];  [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];  self.link = link;}//- (void)Rotate{  //每次旋转6°  self.rotateWheel.transform = CGAffineTransformRotate(self.rotateWheel.transform, M_PI * 2 / 12/ 60 );}

2.点击开始执行旋转动画,

 if (![self.rotateWheel.layer animationForKey:@"zhuandong"]) {        CABasicAnimation* animation = [[CABasicAnimation alloc] init];        animation.keyPath = @"transform.rotation";    animation.toValue = @(2 * M_PI * 5 - M_PI*2/12*(13-self.numberIndex));    animation.duration = 5;        animation.removedOnCompletion = NO;    animation.fillMode = kCAFillModeForwards;        [self.rotateWheel.layer addAnimation:animation forKey:@"zhuandong"];        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(animation.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{            self.rotateWheel.transform = CGAffineTransformMakeRotation(M_PI*2/12*(13-self.numberIndex));      self.link.paused = YES;            [self.rotateWheel.layer removeAnimationForKey:@"zhuandong"];            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"恭喜你!被骗了!!!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];            [alert show];      if (_delegate && [_delegate respondsToSelector:@selector(LuckyDrawViewDidFinishWidthIndex:)]) {        [_delegate LuckyDrawViewDidFinishWidthIndex:self.numberIndex];      }      self.numberIndex = 1;          });  }

3.其间控制转盘最后停留的位置用一个变量控制就行了

@property (nonatomic,assign)NSInteger numberIndex;

效果图

iOS大转盘抽奖images/loading.gif' data-original="http://images2015.cnblogs.com/blog/706432/201603/706432-20160302123643486-1996940521.gif" />

demo链接:http://pan.baidu.com/s/1dDPimiP




原标题:iOS大转盘抽奖

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

建设跨境电商网站:https://www.goluckyvip.com/tag/34615.html
建设外贸网站:https://www.goluckyvip.com/tag/34617.html
建网站:https://www.goluckyvip.com/tag/34619.html
CPC广告:https://www.goluckyvip.com/tag/3462.html
建站程序:https://www.goluckyvip.com/tag/34621.html
建站费用:https://www.goluckyvip.com/tag/34622.html
TikTok 将推出先买后付服务 :https://www.goluckyvip.com/news/188219.html
深圳有没有比较好玩的景点 深圳有没有比较好玩的景点推荐一下:https://www.vstour.cn/a/366175.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流