SnapKit动画效果的实现
来源:互联网 发布:淘宝上便宜的零食店铺 编辑:程序博客网 时间:2024/04/28 00:01
SnapKit动画效果的实现
var view4 : UIView!
var type =true
//创建按钮
func initButton() ->Void {
let btn =UIButton(type: .Custom)
btn.backgroundColor =UIColor.blueColor()
btn.addTarget(self, action:"clickedBtn:", forControlEvents: .TouchUpInside)
self.view.addSubview(btn)
btn.snp_makeConstraints { (make)in
make.centerX.equalTo(self.view)
make.top.equalTo(self.view).offset(100)
make.width.height.equalTo(50)
}
}
//创建视图
func initView4() ->Void {
self.view4 =UIView()
self.view4.backgroundColor = UIColor.greenColor()
self.view.addSubview(self.view4)
self.view4.snp_makeConstraints { (make)in
make.centerX.equalTo(self.view)
make.top.equalTo(self.view).offset(250)
make.width.equalTo(100)
make.height.equalTo(50)
}
}
//按钮的点击方法
func clickedBtn(btn :UIButton) {
ifself.type {
self.type =false
//动画
UIView.animateWithDuration(1, animations: {
//也可以用改变的约束不多,也可以用snp_updateConstraints方法
self.view4.snp_remakeConstraints(closure: { (make)in
make.centerX.equalTo(self.view)
//向下移动110
make.top.equalTo(self.view).offset(250 + 110)
make.width.equalTo(100)
make.height.equalTo(50)
})
//用来立即刷新布局(不写无法实现动画移动,会变成瞬间移动)
self.view.layoutIfNeeded()
})
}
else{
self.type =true
//动画
UIView.animateWithDuration(1, animations: {
self.view4.snp_updateConstraints(closure: { (make)in
//向上移110(移回去)
make.top.equalTo(self.view).offset(250)
})
//用来立即刷新布局(用需要实现动画视图的父视图(self.view),用需要实现动画的视图(self.view4)好像不起作用,不要问我为什么,我写这文章前也不知道为什么,如果有人知道,请在评论里告诉我,谢谢)
self.view.layoutIfNeeded()
//self.view4.layoutIfNeeded()
})
}
}
- SnapKit动画效果的实现
- 动画效果的实现
- 翻页效果的动画实现
- Animation动画效果的实现
- Animation动画效果的实现
- SlidingMenu动画效果的实现
- Animation动画效果的实现
- Animation动画效果的实现
- popwindow动画效果的实现
- Animation动画效果的实现
- 实现倒计时的动画效果
- Animation动画效果的实现
- CSS3的动画效果实现
- 圆弧的动画效果实现
- 加载动画效果的实现
- snapkit的使用
- Flex TitleWindow的动画效果的实现
- UIview的animateWithDuration实现动画的效果
- 最新版本gcc5.3安装详解
- python学习(六):面向对象
- HTML、css、JavaScript 代码分离
- 詩經神學國際論文1:日能習財武經
- servletcontext的使用总结
- SnapKit动画效果的实现
- Oracle学习(二)
- 关于双向链表的审计 audit
- Codova简介
- C#获取本地IP地址兼容win7和xp
- 使用Profiler工具分析内存占用情况
- JS 运动框架2 链式运动
- JSON与XML的区别比较
- 单元测试