import
UIKit
class
ViewController
:
UIViewController
,
UITextFieldDelegate
{
var
txtUser:
UITextField
!
txtPwd:
!
//左手离脑袋的距离
offsetLeftHand:
CGFloat
= 60
//左手图片,右手图片(遮眼睛的)
imgLeftHand:
UIImageView
!
imgRightHand:
!
imgLeftHandGone:
UIImageView
!
imgRightHandGone:
!
//登录框状态
showType:
LoginShowType
=
.
NONE
override
func
viewDidLoad() {
super
.viewDidLoad()
//获取屏幕尺寸
let
mainSize =
UIScreen
.mainScreen().bounds.size
//猫头鹰头部
imgLogin =
(frame:
CGRectMake
(mainSize.width/2-211/2,100,211,109))
imgLogin.image =
UIImage
(named:
"owl-login"
)
imgLogin.layer.masksToBounds =
true
self
.view.addSubview(imgLogin)
//猫头鹰左手(遮眼睛的)
rectLeftHand =
(61 - offsetLeftHand,90,40,65)
imgLeftHand =
(frame:rectLeftHand)
imgLeftHand.image =
"owl-login-arm-left"
)
imgLogin.addSubview(imgLeftHand)
//猫头鹰右手(遮眼睛的)
rectRightHand =
(imgLogin.frame.size.width / 2 + 60,65)
imgRightHand =
(frame:rectRightHand)
imgRightHand.image =
UIImage
"owl-login-arm-right"
)
imgLogin.addSubview(imgRightHand)
//登录框背景
vLogin =
UIView
(15,200,mainSize.width - 30,160))
vLogin.layer.borderWidth = 0.5
vLogin.layer.borderColor =
UIColor
.lightGrayColor().
CGColor
vLogin.backgroundColor =
.whiteColor()
.view.addSubview(vLogin)
//猫头鹰左手(圆形的)
rectLeftHandGone =
CGRectMake
(mainSize.width / 2 - 100,
vLogin.frame.origin.y - 22,40)
imgLeftHandGone =
(frame:rectLeftHandGone)
imgLeftHandGone.image =
"icon_hand"
)
.view.addSubview(imgLeftHandGone)
//猫头鹰右手(圆形的)
rectRightHandGone =
(mainSize.width / 2 + 62,
imgRightHandGone =
(frame:rectRightHandGone)
imgRightHandGone.image =
)
.view.addSubview(imgRightHandGone)
//用户名输入框
txtUser =
UITextField
(30,30,vLogin.frame.size.width - 60,44))
txtUser.delegate =
self
txtUser.layer.cornerRadius = 5
txtUser.layer.borderColor =
CGColor
txtUser.layer.borderWidth = 0.5
txtUser.leftView =
UIView
(0,44,44))
txtUser.leftViewMode =
UITextFieldViewMode
Always
//用户名输入框左侧图标
imgUser =
(frame:
(11,11,22,22))
imgUser.image =
"iconfont-user"
)
txtUser.leftView!.addSubview(imgUser)
vLogin.addSubview(txtUser)
//密码输入框
txtPwd =
txtPwd.delegate =
self
txtPwd.layer.cornerRadius = 5
txtPwd.layer.borderColor =
CGColor
txtPwd.layer.borderWidth = 0.5
txtPwd.secureTextEntry =
true
txtPwd.leftView =
txtPwd.leftViewMode =
Always
//密码输入框左侧图标
imgPwd =
imgPwd.image =
"iconfont-password"
)
txtPwd.leftView!.addSubview(imgPwd)
vLogin.addSubview(txtPwd)
}
//输入框获取焦点开始编辑
textFieldDidBeginEditing(textField:
)
{
//如果当前是用户名输入
if
textField.isEqual(txtUser){
(showType !=
PASS
)
{
showType =
USER
return
}
USER
//播放不遮眼动画
.animateWithDuration(0.5,animations: { () ->
Void
in
.imgLeftHand.frame =
(
.imgLeftHand.frame.origin.x -
.offsetLeftHand,
.imgLeftHand.frame.origin.y + 30,
.imgLeftHand.frame.size.width,
.imgLeftHand.frame.size.height)
.imgRightHand.frame =
(
.imgRightHand.frame.origin.x + 48,
.imgRightHand.frame.origin.y + 30,
.imgRightHand.frame.size.width,monospace!important; min-height:auto!important; background:none!important">.imgRightHand.frame.size.height)
.imgLeftHandGone.frame =
(
.imgLeftHandGone.frame.origin.x - 70,
.imgLeftHandGone.frame.origin.y,40)
.imgRightHandGone.frame =
(
.imgRightHandGone.frame.origin.x + 30,
.imgRightHandGone.frame.origin.y,40)
})
}
//如果当前是密码名输入
else
textField.isEqual(txtPwd){
(showType ==
)
{
PASS
return
}
PASS
//播放遮眼动画
Void
in
(
.imgLeftHand.frame.origin.x +
.imgLeftHand.frame.origin.y - 30,
.imgLeftHand.frame.size.height)
.imgRightHand.frame =
(
.imgRightHand.frame.origin.x - 48,
.imgRightHand.frame.origin.y - 30,
.imgRightHand.frame.size.height)
.imgLeftHandGone.frame =
(
.imgLeftHandGone.frame.origin.x + 70,
(
.imgRightHandGone.frame.origin.x - 30,
})
}
}
didReceiveMemoryWarning() {
.didReceiveMemoryWarning()
}
}
enum
{
case
NONE
USER
PASS
}