最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS實(shí)現(xiàn)新年抽獎(jiǎng)轉(zhuǎn)盤效果的思路

 更新時(shí)間:2020年04月17日 14:41:31   作者:qq_27501365  
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)抽獎(jiǎng)轉(zhuǎn)盤效果的思路,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

臨近春節(jié),相信不少app都會(huì)加一個(gè)新的需求——新年抽獎(jiǎng)

不多廢話,先上GIF效果圖

DEMO鏈接

1. 跑馬燈效果

2. 抽獎(jiǎng)效果

實(shí)現(xiàn)步驟:

一、跑馬燈效果

其實(shí)很簡(jiǎn)單,就是通過以下兩張圖片,用NSTimer無限替換,達(dá)到跑馬燈的效果

bg_lamp_1@2x.png

bg_lamp_2@2x.png

實(shí)現(xiàn)代碼:

_rotaryTable = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth-366*XT)/2, 218*XT, 366*XT, 318*XT)];
_rotaryTable.tag = 100;
[_rotaryTable setImage:[UIImage imageNamed:@"bg_lamp_1"]];
[scrollView addSubview:_rotaryTable];

_itemBordeTImer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(itemBordeTImerEvent) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_itemBordeTImer forMode:NSRunLoopCommonModes];
- (void)itemBordeTImerEvent
{
 if (_rotaryTable.tag == 100) {
 _rotaryTable.tag = 101;
 [_rotaryTable setImage:[UIImage imageNamed:@"bg_lamp_2"]];
 }else if (_rotaryTable.tag == 101){
 _rotaryTable.tag = 100;
 [_rotaryTable setImage:[UIImage imageNamed:@"bg_lamp_1"]];
 }
}

二、抽獎(jiǎng)效果

1.初始化獎(jiǎng)品數(shù)組,以及按照 從上到下,從左到右 的順序布局UI界面

_itemTitleArray = @[@"3跳幣",@"嘉年華門票",@"8跳幣",@"10朵花",@"128朵花",@"2018跳幣",@"528跳幣",@"128跳幣",@"28朵花",@"88跳幣"];
for (int i = 0 ; i < 4; i ++) {
 UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(i*82*XT, 0, 78*XT, 80*XT)];
 [img setImage:[UIImage imageNamed:itemImgArray[i]]];
 [itemView addSubview:img];
 
 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 63*XT, 78*XT, 13*XT)];
 label.textAlignment = NSTextAlignmentCenter;
 label.textColor = [UIColor whiteColor];
 label.font = [UIFont systemFontOfSize:13*XT];
 label.text = _itemTitleArray[I];
 [img addSubview:label];
 }
 
 for (int i = 0 ; i < 2; i ++) {
 UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(i*(78*XT+169*XT), 84*XT, 78*XT, 80*XT)];
 [img setImage:[UIImage imageNamed:itemImgArray[i+4]]];
 [itemView addSubview:img];
 
 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 63*XT, 78*XT, 13*XT)];
 label.textAlignment = NSTextAlignmentCenter;
 label.textColor = [UIColor whiteColor];
 label.font = [UIFont systemFontOfSize:13*XT];
 label.text = _itemTitleArray[i+4];
 [img addSubview:label];
 }
 
 for (int i = 0 ; i < 4; i ++) {
 UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(i*82*XT, 168*XT, 78*XT, 80*XT)];
 [img setImage:[UIImage imageNamed:itemImgArray[i+6]]];
 [itemView addSubview:img];
 
 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 63*XT, 78*XT, 13*XT)];
 label.textAlignment = NSTextAlignmentCenter;
 label.textColor = [UIColor whiteColor];
 label.font = [UIFont systemFontOfSize:13*XT];
 label.text = _itemTitleArray[i+6];
 [img addSubview:label];
 }

2.點(diǎn)擊之后開始抽獎(jiǎng)按鈕后,先快速地將選中框 正時(shí)針 轉(zhuǎn)三圈,再慢速地在 一圈之內(nèi) 旋轉(zhuǎn)至中獎(jiǎng)位置,請(qǐng) 注意 是按照 正時(shí)針 的順序旋轉(zhuǎn),和UI布局的順序不一致,如圖所示:

- (void)getLotteryInfo
{
 // 快速旋轉(zhuǎn)計(jì)數(shù),在NSTimer的方法下自增到29時(shí)結(jié)束,代表選中框快速旋轉(zhuǎn)了三圈,結(jié)束快速旋轉(zhuǎn)
 _fastIndex = 0;

 // 慢速旋轉(zhuǎn)計(jì)數(shù),在NSTimer的方法下自增到下面 _selectedIndex 的數(shù)字時(shí),選中框到達(dá)中獎(jiǎng)位置,結(jié)束慢速旋轉(zhuǎn)
 _slowIndex = -1;

 // 中獎(jiǎng)位置計(jì)數(shù),按照順時(shí)針的順序,如上圖所示,若 _selectedIndex = 9 則獲得 9 所在位置的獎(jiǎng)品
 _selectedIndex = arc4random()%10;
 
 // 根據(jù)獎(jiǎng)品數(shù)組,獲取中獎(jiǎng)信息
 if (_selectedIndex<4) {
 _result = _itemTitleArray[_selectedIndex];
 }else if (_selectedIndex == 4){
 _result = @"2018跳幣";
 }else if (_selectedIndex == 5){
 _result = @"88跳幣";
 }else if (_selectedIndex == 6){
 _result = @"28朵花";
 }else if (_selectedIndex == 7){
 _result = @"128跳幣";
 }else if (_selectedIndex == 8){
 _result = @"528跳幣";
 }else if (_selectedIndex == 9){
 _result = @"128朵花";
 }
 _itemBorderView.hidden = NO;

 // 開啟快速旋轉(zhuǎn),時(shí)間間隔為0.1秒
 _fastTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fastTimerEvent) userInfo:nil repeats:YES];
 [[NSRunLoop currentRunLoop] addTimer:_fastTimer forMode:NSRunLoopCommonModes];
}

3.NSTimer 快速旋轉(zhuǎn)事件

- (void)fastTimerEvent
{
 // _fastIndex 自增
 _fastIndex = _fastIndex + 1;

 // 順時(shí)針移動(dòng)選中框的位置
 if (_fastIndex % 10 == 0) {
 [_itemBorderView setFrame:CGRectMake(-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 1){
 [_itemBorderView setFrame:CGRectMake(82*XT-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 2){
 [_itemBorderView setFrame:CGRectMake(2*82*XT-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 3){
 [_itemBorderView setFrame:CGRectMake(3*82*XT-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 4){
 [_itemBorderView setFrame:CGRectMake(3*82*XT-1*XT, 84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 5){
 [_itemBorderView setFrame:CGRectMake(3*82*XT-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 6){
 [_itemBorderView setFrame:CGRectMake(2*82*XT-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 7){
 [_itemBorderView setFrame:CGRectMake(82*XT-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 8){
 [_itemBorderView setFrame:CGRectMake(-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_fastIndex % 10 == 9){
 [_itemBorderView setFrame:CGRectMake(-1*XT, 84*XT-1*XT, 80*XT, 82*XT)];
 }

 // _fastIndex = 29 時(shí)選中框結(jié)束快速旋轉(zhuǎn),開啟慢速旋轉(zhuǎn),時(shí)間間隔為0.45秒
 if (_fastIndex >= 29) {
 [_fastTimer invalidate];
 _slowTimer = [NSTimer scheduledTimerWithTimeInterval:0.45 target:self selector:@selector(slowTimerEvent) userInfo:nil repeats:YES];
 [[NSRunLoop currentRunLoop] addTimer:_slowTimer forMode:NSRunLoopCommonModes];
 }
}

4.NSTimer 慢速旋轉(zhuǎn)事件

// 慢速移動(dòng)動(dòng)畫
- (void)slowTimerEvent
{
 // _slowIndex 自增
 _slowIndex = _slowIndex + 1;

 // 順時(shí)針移動(dòng)轉(zhuǎn)中框的位置
 if (_slowIndex % 10 == 0) {
 [_itemBorderView setFrame:CGRectMake(-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 1){
 [_itemBorderView setFrame:CGRectMake(82*XT-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 2){
 [_itemBorderView setFrame:CGRectMake(2*82*XT-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 3){
 [_itemBorderView setFrame:CGRectMake(3*82*XT-1*XT, -1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 4){
 [_itemBorderView setFrame:CGRectMake(3*82*XT-1*XT, 84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 5){
 [_itemBorderView setFrame:CGRectMake(3*82*XT-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 6){
 [_itemBorderView setFrame:CGRectMake(2*82*XT-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 7){
 [_itemBorderView setFrame:CGRectMake(82*XT-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 8){
 [_itemBorderView setFrame:CGRectMake(-1*XT, 2*84*XT-1*XT, 80*XT, 82*XT)];
 }else if (_slowIndex % 10 == 9){
 [_itemBorderView setFrame:CGRectMake(-1*XT, 84*XT-1*XT, 80*XT, 82*XT)];
 }

 // 當(dāng) _slowIndex >= _selectedIndex 時(shí)選中框結(jié)束慢速旋轉(zhuǎn),開啟中獎(jiǎng)獎(jiǎng)品界面
 if (_slowIndex >= _selectedIndex) {
 [_slowTimer invalidate];

 dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5/*延遲執(zhí)行時(shí)間*/ * NSEC_PER_SEC));
 dispatch_after(delayTime, dispatch_get_main_queue(), ^{
 self.startButton.userInteractionEnabled = YES;
 [self showLotteryRlesultView];
 });
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 代碼詳解iOS視頻直播彈幕功能

    代碼詳解iOS視頻直播彈幕功能

    本篇文章通過原理分析和代碼實(shí)例講述了實(shí)現(xiàn)iOS視頻直播彈幕功能的方法,需要的朋友參考學(xué)習(xí)下吧。
    2017-12-12
  • iOS實(shí)現(xiàn)無限滑動(dòng)效果

    iOS實(shí)現(xiàn)無限滑動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)無限滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • iOS屏幕根據(jù)鍵盤自動(dòng)變化高度

    iOS屏幕根據(jù)鍵盤自動(dòng)變化高度

    這篇文章主要為大家詳細(xì)介紹了iOS屏幕根據(jù)鍵盤自動(dòng)變化高度,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • iOS 16 CocoaAsyncSocket 崩潰修復(fù)詳解

    iOS 16 CocoaAsyncSocket 崩潰修復(fù)詳解

    這篇文章主要為大家介紹了iOS 16 CocoaAsyncSocket 崩潰修復(fù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • iOS中使用schema協(xié)議調(diào)用APP和使用iframe打開APP的例子

    iOS中使用schema協(xié)議調(diào)用APP和使用iframe打開APP的例子

    這篇文章主要介紹了iOS中使用schema協(xié)議調(diào)用APP和使用iframe打開APP的例子,用在瀏覽器中打開APP,需要的朋友可以參考下
    2014-08-08
  • iOS開發(fā)筆記之鍵盤、靜態(tài)庫(kù)、動(dòng)畫和Crash定位

    iOS開發(fā)筆記之鍵盤、靜態(tài)庫(kù)、動(dòng)畫和Crash定位

    最近在學(xué)習(xí)iOS開發(fā),進(jìn)行了一些實(shí)戰(zhàn),所以下面這篇文章主要給大家介紹了關(guān)于iOS開發(fā)筆記之鍵盤、靜態(tài)庫(kù)、動(dòng)畫和Crash定位的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2018-04-04
  • IOS Xcode調(diào)試常用命令和斷點(diǎn)整理

    IOS Xcode調(diào)試常用命令和斷點(diǎn)整理

    這篇文章主要介紹了IOS Xcode調(diào)試常用命令和斷點(diǎn)整理的相關(guān)資料,這里對(duì)IOS Xcode調(diào)試常用命令進(jìn)行了總結(jié),需要的朋友可以參考下
    2016-12-12
  • iOS15適配小結(jié)

    iOS15適配小結(jié)

    本文主要介紹了iOS15適配小結(jié),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • iOS中創(chuàng)建Model的最佳實(shí)踐記錄

    iOS中創(chuàng)建Model的最佳實(shí)踐記錄

    這篇文章主要給大家介紹了關(guān)于iOS中創(chuàng)建Model的最佳實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用iOS具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-10-10
  • IOS 實(shí)現(xiàn)微信自動(dòng)搶紅包(非越獄IPhone)

    IOS 實(shí)現(xiàn)微信自動(dòng)搶紅包(非越獄IPhone)

    這篇文章主要介紹了IOS 實(shí)現(xiàn)微信自動(dòng)搶紅包(非越獄IPhone)的相關(guān)資料,這里對(duì)實(shí)現(xiàn)自動(dòng)搶紅包做一個(gè)詳細(xì)的實(shí)現(xiàn)步驟,需要的朋友可以參考下
    2016-11-11

最新評(píng)論

马关县| 青海省| 资中县| 盐池县| 玉山县| 星子县| 达孜县| 峨山| 布拖县| 曲松县| 故城县| 通许县| 油尖旺区| 尉氏县| 扶风县| 年辖:市辖区| 柳河县| 华亭县| 宝山区| 六盘水市| 长寿区| 左云县| 日喀则市| 柳林县| 纳雍县| 襄城县| 青铜峡市| 酒泉市| 珲春市| 夏河县| 阳山县| 临江市| 广昌县| 门源| 普兰县| 静安区| 永寿县| 喀喇沁旗| 聊城市| 治县。| 汾阳市|