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

iOS實(shí)現(xiàn)轉(zhuǎn)盤效果

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

本文實(shí)例為大家分享了iOS實(shí)現(xiàn)轉(zhuǎn)盤效果的具體代碼,供大家參考,具體內(nèi)容如下

Demo下載地址: iOS轉(zhuǎn)盤效果

功能:實(shí)現(xiàn)了常用的iOS轉(zhuǎn)盤效果,輪盤抽獎(jiǎng)效果的實(shí)現(xiàn),轉(zhuǎn)盤可以暫停,旋轉(zhuǎn),已經(jīng)快速旋轉(zhuǎn)抽獎(jiǎng),選中的效果指向正上方。

效果圖:

工程文件目錄:

核心代碼:

//
// ViewController.m
// 轉(zhuǎn)盤效果
//
// Created by llkj on 2017/8/31.
// Copyright © 2017年 LayneCheung. All rights reserved.
//

#import "ViewController.h"
#import "WheelView.h"

@interface ViewController ()

@property (nonatomic, weak) WheelView *wheelV;
@end

@implementation ViewController

- (void)viewDidLoad {
 [super viewDidLoad];

 WheelView *wheelV = [WheelView wheelView];
 wheelV.center = self.view.center;
 self.wheelV = wheelV;
 [self.view addSubview:wheelV];


}

- (IBAction)rotation:(id)sender {
 [self.wheelV rotation];
}

- (IBAction)stop:(id)sender {
 [self.wheelV stop];
}

- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.
}


@end

WheelView文件

//
// WheelView.h
// 轉(zhuǎn)盤效果
//
// Created by llkj on 2017/8/31.
// Copyright © 2017年 LayneCheung. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface WheelView : UIView

+ (instancetype)wheelView;

- (void)rotation;
- (void)stop;
@end
//
// WheelView.m
// 轉(zhuǎn)盤效果
//
// Created by llkj on 2017/8/31.
// Copyright © 2017年 LayneCheung. All rights reserved.
//

#import "WheelView.h"
#import "WheelBtn.h"

#define angle2Rad(angle) ((angle) / 180.0 * M_PI)

@interface WheelView ()<CAAnimationDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *contentV;

@property (nonatomic, weak) UIButton *selectBtn;

@property (nonatomic, strong) CADisplayLink *link;
@end

@implementation WheelView

- (CADisplayLink *)link {

 if (_link == nil) {
 CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
 [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
 _link = link;
 }
 return _link;
}
+ (instancetype)wheelView {

 return [[[NSBundle mainBundle] loadNibNamed:@"WheelView" owner:nil options:nil] lastObject];
}


- (instancetype)initWithFrame:(CGRect)frame
{
 self = [super initWithFrame:frame];
 if (self) {
 self = [[[NSBundle mainBundle] loadNibNamed:@"WheelView" owner:nil options:nil] lastObject];
 }
 return self;
}

- (void)awakeFromNib {
 [super awakeFromNib];

 CGFloat btnW = 68;
 CGFloat btnH = 143;
 CGFloat angle = 0;

 //加載原始大圖片
 UIImage *oriImage = [UIImage imageNamed:@"LuckyAstrology"];
 //加載原始選中的大圖片
 UIImage *oriSelImg = [UIImage imageNamed:@"LuckyAstrologyPressed"];

 CGFloat X = 0;
 CGFloat Y = 0;
 CGFloat sacle = [UIScreen mainScreen].scale;
 CGFloat clipW = oriImage.size.width / 12.0 * sacle;
 CGFloat clipH = oriImage.size.height * sacle;

 for (int i = 0; i < 12; i ++) {

 WheelBtn *btn = [WheelBtn buttonWithType:UIButtonTypeCustom];
 btn.bounds = CGRectMake(0, 0, btnW, btnH);

 //按鈕正常狀態(tài)圖片
 X = i * clipW;
 //給定一張圖片截取指定區(qū)域內(nèi)的圖片
 CGImageRef clipImg = CGImageCreateWithImageInRect(oriImage.CGImage, CGRectMake(X, Y, clipW, clipH));
 [btn setImage:[UIImage imageWithCGImage:clipImg] forState:UIControlStateNormal];

 //按鈕選中狀態(tài)圖片
 CGImageRef clipSelImg = CGImageCreateWithImageInRect(oriSelImg.CGImage, CGRectMake(X, Y, clipW, clipH));
 [btn setImage:[UIImage imageWithCGImage:clipSelImg] forState:UIControlStateSelected];

 [btn setBackgroundImage:[UIImage imageNamed:@"LuckyRototeSelected"] forState:UIControlStateSelected];
 btn.layer.anchorPoint = CGPointMake(0.5, 1);
 btn.layer.position = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5);

 btn.transform = CGAffineTransformMakeRotation(angle2Rad(angle));
 angle += 30;

 [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
 [self.contentV addSubview:btn];

 //默認(rèn)第一個(gè)按鈕選中
 if (i == 0) {
  [self btnClick:btn];
 }
 }
}

- (void)btnClick:(UIButton *)btn {

 //1.讓當(dāng)前選中的按鈕取消選中
 self.selectBtn.selected = NO;
 //2.讓當(dāng)前點(diǎn)擊的按鈕成為選中狀態(tài)
 btn.selected = YES;
 //3.當(dāng)前點(diǎn)擊的按鈕成為選中狀態(tài)
 self.selectBtn = btn;


}
- (void)rotation {

 self.link.paused = NO;
}

- (void)stop {

 self.link.paused = YES;
}

- (void)update {

 self.contentV.transform = CGAffineTransformRotate(self.contentV.transform, M_PI / 300.0);

}

- (IBAction)start:(id)sender {

 //快速轉(zhuǎn)幾圈
 CABasicAnimation *anim = [CABasicAnimation animation];
 anim.keyPath = @"transform.rotation";
 anim.toValue = @(M_PI * 4);
 anim.duration = 0.5;
 anim.repeatCount = 1;
 anim.delegate = self;
 [self.contentV.layer addAnimation:anim forKey:nil];

}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

 CGAffineTransform transform = self.selectBtn.transform;
 //獲取當(dāng)前選中按鈕的旋轉(zhuǎn)角度
 CGFloat angle = atan2(transform.b, transform.a);

 //動(dòng)畫結(jié)束時(shí)當(dāng)前選中的按鈕指向最上方
 self.contentV.transform = CGAffineTransformMakeRotation(-angle);
}

@end

WheelBtn.m

//
// WheelBtn.m
// 轉(zhuǎn)盤效果
//
// Created by llkj on 2017/8/31.
// Copyright © 2017年 LayneCheung. All rights reserved.
//

#import "WheelBtn.h"

@implementation WheelBtn

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

 CGRect rect = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height * 0.5);

 if (CGRectContainsPoint(rect, point)) {
 // 在指定的范圍內(nèi)
 return [super hitTest:point withEvent:event];
 } else {
 return nil;
 }
}
//取消按鈕高亮狀態(tài)做的事
- (void)setHighlighted:(BOOL)highlighted {


}

//返回當(dāng)前按鈕中的image位置和尺寸
- (CGRect)imageRectForContentRect:(CGRect)contentRect {

 return CGRectMake((contentRect.size.width - 40) *0.5, 20, 40, 48);
}

//返回當(dāng)前按鈕中的Label位置和尺寸
//- (CGRect)titleRectForContentRect:(CGRect)contentRect{
//
//}
@end

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

相關(guān)文章

  • Xcode8 更新解決模擬器找不到的方法

    Xcode8 更新解決模擬器找不到的方法

    這篇文章主要介紹了Xcode8 更新解決模擬器找不到的方法的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • iOS?block的值捕獲與指針捕獲詳解

    iOS?block的值捕獲與指針捕獲詳解

    Block它是C語(yǔ)言級(jí)別和運(yùn)行時(shí)方面的一個(gè)特征,下面這篇文章主要給大家介紹了關(guān)于iOS?block的值捕獲與指針捕獲的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-02-02
  • iOS App通信之local socket示例

    iOS App通信之local socket示例

    這篇文章主要介紹了iOS App之間的通信 -local socket示例的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • iOS生成圖片數(shù)字字母驗(yàn)證效果

    iOS生成圖片數(shù)字字母驗(yàn)證效果

    這篇文章主要為大家詳細(xì)介紹了iOS生成圖片數(shù)字字母驗(yàn)證效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • IOS 添加自定義字體方法詳解

    IOS 添加自定義字體方法詳解

    這篇文章主要介紹了IOS 添加自定義字體方法詳解的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • iOS中Cell的Section展開和收起的示例代碼

    iOS中Cell的Section展開和收起的示例代碼

    本篇文章主要介紹了iOS中Cell的Section展開和收起的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • iOS如何自定義啟動(dòng)界面實(shí)例詳解

    iOS如何自定義啟動(dòng)界面實(shí)例詳解

    當(dāng)我們打開一款應(yīng)用程序的時(shí)候,首先映入眼簾的往往并不是程序的主界面,而是經(jīng)過(guò)精心設(shè)計(jì)的歡迎界面,這個(gè)界面通常會(huì)停留幾秒鐘,然后消失。下面這篇文章主要給大家介紹了關(guān)于iOS如何自定義啟動(dòng)界面的相關(guān)資料,需要的朋友可以參考下。
    2017-12-12
  • iOS開發(fā)創(chuàng)建frame實(shí)現(xiàn)window窗口view視圖示例

    iOS開發(fā)創(chuàng)建frame實(shí)現(xiàn)window窗口view視圖示例

    這篇文章主要為大家介紹了iOS開發(fā)創(chuàng)建frame實(shí)現(xiàn)window窗口view視圖示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • iOS實(shí)現(xiàn)轉(zhuǎn)盤效果

    iOS實(shí)現(xiàn)轉(zhuǎn)盤效果

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)轉(zhuǎn)盤效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • HTTP/2 協(xié)議用于 iOS 推送提醒服務(wù) (APNS)

    HTTP/2 協(xié)議用于 iOS 推送提醒服務(wù) (APNS)

    基于JSON的請(qǐng)求和響應(yīng)對(duì)于每個(gè)通知,如果成功響應(yīng),將會(huì)返回200標(biāo)識(shí) - 不用再去猜測(cè)通知是否被接收到響應(yīng)錯(cuò)誤將會(huì)以JSON字符消息的長(zhǎng)度從2048個(gè)字節(jié)增加到4096個(gè)字節(jié)連接狀態(tài)可以通過(guò)HTTP/2的ping框架來(lái)進(jìn)行檢查.
    2016-04-04

最新評(píng)論

江陵县| 剑阁县| 兴海县| 林周县| 辽宁省| 含山县| 八宿县| 弥渡县| 阿尔山市| 八宿县| 宣威市| 湟中县| 石林| 文成县| 永城市| 长海县| 伽师县| 兴义市| 竹溪县| 靖江市| 西吉县| 乌什县| 松滋市| 龙游县| 通化县| 碌曲县| 筠连县| 平顶山市| 奉化市| 格尔木市| 牟定县| 泰安市| 明星| 遵义市| 开鲁县| 宝兴县| 时尚| 唐河县| 屏东市| 无棣县| 华蓥市|