Latest 1.0.0
Homepage https://github.com/kejinlu/KKGestureLockView
License Modified BSD Copyright (c) 2012 Luke. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Platforms ios 5.0, requires ARC
Authors

介绍

KKGestureLockView是一个非常方便使用的Gesture Lock控件,只需要简单的几步便可以在你的app中实现如安卓那样的手势解锁的效果。其实之前并不看好这种解锁的方式,不过上次发现支付宝iOS新版app中使用了这样的形式来进行功能的解锁,觉得也还方便。此控件有几个概念先说明一下:

  • 在控件中,每一个节点叫做一个gesture node,当手势经过某个节点的时候,那么这个节点便进入选中状态,成为最终passcode序列中的一部分
  • 每一个节点可以有两种状态,一种是普通状态,一种是选中状态,可以分别为这两种状态设置节点的图片:normalGestureNodeImageselectedGestureNodeImage
  • 连线也是可以自定义的,可以通过lineColorlineWidth来设置连线的颜色和宽度
  • 节点所在的容器称之为contentView,contentView到KKGestureLockView的四边距离使用contentInsets来描述,手势在KKGestureLockView的区域内是不会被结束的,但是Line连线的绘制只会在contentView的区域内
  • 节点的个数以及每行的节点数都是可以自定义的,分别通过numberOfGestureNodesgestureNodesPerRow进行设置;每一个节点按照从左到右从上到下的方式进行编号,编号从0开始;为了支持多于10个节点的情况,所以passcode并没有使用节点序号直接串联,而是使用半角逗号分隔所有选中节点的序号, 比如上图中的passcode即为 0,1,4
  • 提供了三个delegate方法,用于通知delegate相关的事件

用法

控件的源码在KKGestureLockView/Source目录下,且自带了一个仿支付宝解锁界面的例子(例子的图片资源取自支付宝app解压缩后的资源图片):

self.lockView.normalGestureNodeImage = [UIImage imageNamed:@"gesture_node_normal.png"];
self.lockView.selectedGestureNodeImage = [UIImage imageNamed:@"gesture_node_selected.png"];
self.lockView.lineColor = [[UIColor orangeColor] colorWithAlphaComponent:0.3];
self.lockView.lineWidth = 12;
self.lockView.delegate = self;
self.lockView.contentInsets = UIEdgeInsetsMake(150, 20, 100, 20);

一般情况下9个节点便够用了,当然如果你想多弄些节点也不是不可以:

Latest podspec

{
    "name": "KKGestureLockView",
    "version": "1.0.0",
    "summary": "A Gesture Lock View For iOS.",
    "homepage": "https://github.com/kejinlu/KKGestureLockView",
    "authors": {
        "Luke": "[email protected]"
    },
    "source": {
        "git": "https://github.com/kejinlu/KKGestureLockView.git",
        "tag": "1.0.0"
    },
    "source_files": "KKGestureLockView/Source/*.{h,m}",
    "requires_arc": true,
    "platforms": {
        "ios": "5.0"
    },
    "license": {
        "type": "Modified BSD",
        "text": "              Copyright (c) 2012 Luke. All rights reserved.nn              Redistribution and use in source and binary forms, with or withoutn              modification, are permitted provided that the following conditionsn              are met:n              1. Redistributions of source code must retain the above copyrightn              notice, this list of conditions and the following disclaimer.n              2. Redistributions in binary form must reproduce the above copyrightn              notice, this list of conditions and the following disclaimer in then              documentation and/or other materials provided with the distribution.n              3. The name of the author may not be used to endorse or promote productsn              derived from this software without specific prior written permission.nn              THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS ORn              IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIESn              OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.n              IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,n              INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUTn              NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,n              DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANYn              THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORTn              (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OFn              THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.n"
    }
}

Pin It on Pinterest

Share This