Day12 - 约束动画

效果图

效果图

<br />

1、UI布局 第一个页面的布局很简单,就不做介绍了

  • 重点讲下第二个的页面的布局
    1.1、在Main.storyboard中拖入一个ViewController
设置大小

<br />
1.2、拖入一个imageView,并设置约束下左右为0 上 -20

效果图

<br />
1.3、添加返回按钮和标题
拖入button


按钮

<br />
拖入label,设置字体居中


label
label

<br />

1.4 拖入两个textfiled
选择第一个拖入的textfiled

第一个textfiled

选择第二个textfiled,按住ctrl键

设置如图

如图

<br />
1.5、拖入一个button

第一步
第二步

<br />
然后在自己选择背景颜色,placehloder,设置image最后效果如下

最终效果

<br />
<br /><br />

2、创建一个类,继承ViewController,并且和拖入的ViewController进行关联

然后把textfiled、button拖入到你创建的ViewController中

  • 然后在点击storyboard中的textfiled
把约束拖入到Viewcontroller中

再次使用上面的方法把密码框的约束也拖入到viewcontroller中
首先先声明属性:PS(你的命名可以与我的不同,自己做出相应的修改)

//账号
    @IBOutlet weak var account: UITextField!

    //密码
    @IBOutlet weak var password: UITextField!
    
    //登录
    @IBOutlet weak var loginBtn: UIButton!
    
    //密码的约束
    @IBOutlet weak var passwordLine: NSLayoutConstraint!
    //账号的约束
    @IBOutlet weak var accouneLine: NSLayoutConstraint!
    
    //按钮的bounds
    var btnBounds : CGRect! = CGRectZero

然后重写下面两个方法

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        passwordLine.constant -= UIScreen.mainScreen().bounds.width
        accouneLine.constant -= UIScreen.mainScreen().bounds.width
        
        btnBounds = loginBtn.bounds
    }
    
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        UIView.animateWithDuration(0.75) {
            self.accouneLine.constant = 0
            self.view.layoutIfNeeded()
        }
        
        UIView.animateWithDuration(0.75, delay: 0.2, options: UIViewAnimationOptions.CurveLinear, animations: {
            self.passwordLine.constant = 0
            self.view.layoutIfNeeded()
            }, completion: nil)
    }

<br />
监听登录按钮点击事件和按下事件

@IBAction func btnTouchDown(sender: UIButton) {
        UIView.animateWithDuration(0.25) { 
            sender.bounds = CGRect(x: self.btnBounds.origin.x + 20, y: 0, width: self.btnBounds.size.width - 40, height: self.btnBounds.size.height)
        }
    }
    
    @IBAction func loginBtnClick(sender: UIButton) {
        UIView.animateWithDuration(0.75, delay: 0, usingSpringWithDamping: 0.35, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
            sender.enabled = false
            sender.bounds = CGRect(x: self.btnBounds.origin.x - 40, y: self.btnBounds.origin.y, width: self.btnBounds.size.width + 80, height: self.btnBounds.size.height)
            
            }) { (_) in
                sender.enabled = true
        }
    }

<br />
监听返回按钮的点击事件

@IBAction func btn(sender: UIButton) {
        dismissViewControllerAnimated(true, completion: nil)
    }

<br />
最后在ViewDidLoad中设置圆角

override func viewDidLoad() {
        super.viewDidLoad()
        loginBtn.layer.cornerRadius = 5
        account.layer.cornerRadius = 5
        password.layer.cornerRadius = 5
        
        
    }

<br />

Demo - buttonAnimation

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,762评论 4 61
  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,458评论 30 472
  • iOS 实战开发课程笔记 本贴旨在作为对极客班 《iOS 开发实战》第五期期课程视频重新学习的笔记。目标是建立一个...
    黄穆斌阅读 8,296评论 12 57
  • Feats of memory anyone can do TED简介:有人能在很短时间内背下上千个数字,或是记下...
    TED博物馆阅读 7,036评论 0 2
  • 今天难得全家总动员,我们一起去了兰陵生态园,在里面,我第一次见到世界上最大的南瓜,第一次见到了全部用生姜堆成...
    Doris66666阅读 5,051评论 0 0

友情链接更多精彩内容