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

iOS實(shí)現(xiàn)九宮格連線手勢(shì)解鎖

 更新時(shí)間:2020年04月18日 15:53:12   作者:LayneCheung  
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)九宮格連線手勢(shì)解鎖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iOS實(shí)現(xiàn)九宮格連線手勢(shì)解鎖的具體代碼,供大家參考,具體內(nèi)容如下

Demo下載地址:手勢(shì)解鎖

效果圖:

核心代碼:

//
// ClockView.m
// 手勢(shì)解鎖
//
// Created by llkj on 2017/8/24.
// Copyright © 2017年 LayneCheung. All rights reserved.
//

#import "ClockView.h"

@interface ClockView ()

//存放當(dāng)前選中的按鈕
@property (nonatomic, strong) NSMutableArray *selectBtnArry;

//當(dāng)前手指所在點(diǎn)
@property (nonatomic, assign) CGPoint curP;

@end

@implementation ClockView

- (void)awakeFromNib{

 [super awakeFromNib];

 //初始化
 [self setUp];
}

- (NSMutableArray *)selectBtnArry{

 if (_selectBtnArry == nil) {
 _selectBtnArry = [NSMutableArray array];
 }
 return _selectBtnArry;
}

- (void)setUp{

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

 //創(chuàng)建按鈕
 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

 btn.tag = i;

 btn.userInteractionEnabled = NO;

 [btn setImage:[UIImage imageNamed:@"gesture_node_normal"] forState:UIControlStateNormal];

 [btn setImage:[UIImage imageNamed:@"gesture_node_selected"] forState:UIControlStateSelected];

 [self addSubview:btn];
 }
}

//獲取當(dāng)前點(diǎn)
- (CGPoint)getCurrentPoint:(NSSet *)point{

 UITouch *touch = [point anyObject];
 return [touch locationInView:self];

}

//返回按鈕
- (UIButton *)btnRectContainsPoint:(CGPoint)point{

 //遍歷brn判斷當(dāng)前點(diǎn)在不在btn上
 for (UIButton *btn in self.subviews) {
 if (CGRectContainsPoint(btn.frame, point)) {
  return btn;
 }
 }
 return nil;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

 //1.獲取當(dāng)前點(diǎn)
 CGPoint curP = [self getCurrentPoint:touches];

 //2.判斷當(dāng)前點(diǎn)在不在btn上
 UIButton *btn = [self btnRectContainsPoint:curP];
 if (btn && btn.selected == NO) {
 btn.selected = YES;

 //保存選中的按鈕
 [self.selectBtnArry addObject:btn];
 }

}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

 //1.獲取當(dāng)前點(diǎn)
 CGPoint curP = [self getCurrentPoint:touches];
 self.curP = curP;

 //2.判斷當(dāng)前點(diǎn)在不在btn上
 UIButton *btn = [self btnRectContainsPoint:curP];
 if (btn && btn.selected == NO) {
 btn.selected = YES;

 //保存選中的按鈕
 [self.selectBtnArry addObject:btn];
 }
 //重繪
 [self setNeedsDisplay];
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

 NSMutableString *str = [NSMutableString string];
 //1.取消所有選中的按鈕
 for (UIButton *btn in self.selectBtnArry) {
 btn.selected = NO;
 [str appendFormat:@"%ld", btn.tag];
 }
 //2.清空路徑
 [self.selectBtnArry removeAllObjects];
 [self setNeedsDisplay];

 //查看是否是第一次設(shè)置密碼
 NSString *keyPwd = [[NSUserDefaults standardUserDefaults] objectForKey:@"keyPwd"];
 if (!keyPwd) {
 [[NSUserDefaults standardUserDefaults] setObject:str forKey:@"keyPwd"];
 [[NSUserDefaults standardUserDefaults] synchronize];

 UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"第一次設(shè)置密碼成功" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
 [alertV show];
 NSLog(@"第一次輸入密碼");
 }else{

 if ([keyPwd isEqualToString:str]) {
  NSLog(@"密碼正確");
  UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"手勢(shì)輸入正確" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
  [alertV show];


 }else{
  NSLog(@"密碼錯(cuò)誤");
  UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"手勢(shì)輸入錯(cuò)誤" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
  [alertV show];
 }
 }
 //3.查看當(dāng)前選中按鈕的順序
 NSLog(@"選中按鈕順序?yàn)?%@",str);
}

- (void)drawRect:(CGRect)rect{

 if (self.selectBtnArry.count) {
 //1.創(chuàng)建路徑
 UIBezierPath *path = [UIBezierPath bezierPath];

 //2.取出所有保存的按鈕
 for (int i = 0; i < self.selectBtnArry.count; i ++) {
  UIButton *btn = self.selectBtnArry[i];

  //當(dāng)前按鈕是不是第一個(gè)按鈕
  if (i == 0) {
  //設(shè)置成路徑的起點(diǎn)
  [path moveToPoint:btn.center];
  } else {
  //添加一根線到按鈕中心
  [path addLineToPoint:btn.center];
  }
 }

 //添加一根線到當(dāng)前手指所在點(diǎn)
 [path addLineToPoint:self.curP];

 //設(shè)置線寬/顏色
 [path setLineWidth:5];
 [[UIColor whiteColor] set];
 [path setLineJoinStyle:kCGLineJoinRound];

 //3.繪制路徑
 [path stroke];
 }


}
- (void)layoutSubviews{

 [super layoutSubviews];

 CGFloat x = 0;
 CGFloat y = 0;

 CGFloat btnWH = 75;

 int column = 3;
 int margin = (self.bounds.size.width - (column * btnWH)) / (column + 1);

 int currentColumn = 0;
 int currentRow = 0;

 for (int i = 0; i < self.subviews.count; i ++) {

 // 求當(dāng)前所在的列
 currentColumn = i % column;

 // 求當(dāng)前所在的行
 currentRow = i / column;

 x = margin + (btnWH + margin) * currentColumn;

 y = margin + (btnWH + margin) * currentRow;

 UIButton *btn = self.subviews[i];

 btn.frame = CGRectMake(x, y, btnWH, btnWH);
 }
}
@end

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

相關(guān)文章

  • IOS中UIImageView方法實(shí)現(xiàn)簡(jiǎn)單動(dòng)畫(huà)

    IOS中UIImageView方法實(shí)現(xiàn)簡(jiǎn)單動(dòng)畫(huà)

    這篇文章主要介紹了IOS中UIImageView方法實(shí)現(xiàn)簡(jiǎn)單動(dòng)畫(huà)的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • iOS代碼瘦身實(shí)踐之如何刪除無(wú)用的類(lèi)

    iOS代碼瘦身實(shí)踐之如何刪除無(wú)用的類(lèi)

    這篇文章主要給大家介紹了關(guān)于iOS代碼瘦身實(shí)踐之如何刪除無(wú)用的類(lèi),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家各位iOS開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • iOS UIImageView圖片自動(dòng)拉伸功能

    iOS UIImageView圖片自動(dòng)拉伸功能

    這篇文章主要介紹了iOS UIImageView圖片自動(dòng)拉伸功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • iOS的UI開(kāi)發(fā)中Button的基本編寫(xiě)方法講解

    iOS的UI開(kāi)發(fā)中Button的基本編寫(xiě)方法講解

    這篇文章主要介紹了iOS的UI開(kāi)發(fā)中Button的基本編寫(xiě)方法講解,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2015-11-11
  • iOS開(kāi)發(fā)系列--通知與消息機(jī)制詳解

    iOS開(kāi)發(fā)系列--通知與消息機(jī)制詳解

    這篇文章主要介紹了iOS開(kāi)發(fā)系列--通知與消息機(jī)制詳解,有需要的同學(xué)可以了解一下。
    2016-11-11
  • Framework中實(shí)現(xiàn)OC和Swift的混編方案

    Framework中實(shí)現(xiàn)OC和Swift的混編方案

    這篇文章主要為大家介紹了Framework中實(shí)現(xiàn)OC和Swift的混編方案詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • iOS中block的定義與使用

    iOS中block的定義與使用

    蘋(píng)果官方文檔聲明,block是objc對(duì)象。下面這篇文章主要給大家介紹了關(guān)于iOS中block的定義與使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位iOS開(kāi)發(fā)者具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • iOS App開(kāi)發(fā)中UIViewController類(lèi)的使用教程

    iOS App開(kāi)發(fā)中UIViewController類(lèi)的使用教程

    UIViewController是iOS中控制視圖的關(guān)鍵所在,這里我們將針對(duì)UIViewController的聲明周期與主要屬性和方法,來(lái)總結(jié)iOS App開(kāi)發(fā)中UIViewController類(lèi)的使用教程
    2016-07-07
  • iOS runtime知識(shí)梳理

    iOS runtime知識(shí)梳理

    本文主要對(duì)iOS runtime的知識(shí)進(jìn)行梳理。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-01-01
  • WKWebView、WebView和JS的交互方式詳解

    WKWebView、WebView和JS的交互方式詳解

    這篇文章主要給大家介紹了關(guān)于WKWebView、WebView和JS的交互方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位iOS開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04

最新評(píng)論

手机| 永春县| 乐业县| 侯马市| 沅江市| 自贡市| 诏安县| 武威市| 呼图壁县| 双牌县| 广平县| 金川县| 彭泽县| 高阳县| 社旗县| 兴宁市| 磐石市| 綦江县| 吉木萨尔县| 井研县| 万州区| 江源县| 安陆市| 类乌齐县| 陆川县| 中牟县| 东台市| 普陀区| 开化县| 龙口市| 宜昌市| 日照市| 偏关县| 榆树市| 灵武市| 黎平县| 西畴县| 易门县| 阳曲县| 二手房| 齐河县|