iOS Swift最简单的Animation
最近发现Animation是一个iOS开发中非常好玩的元素,能给应用的交互性增色不少。比如很多音乐应用的菜单从底部弹出和隐藏的效果。
Animation最核心的当然就是UIView的animateWithDuration这个类方法了,另外有个博客介绍了很多animation的文章也很不错:
http://www.devtalking.com/articles/uiview-animation-practice/
念在好久没用swift开发了,于是花了几分钟写了个简单的demo复习下
//
// ViewController.swift
// UIAnimationTest
//
// Created by shen on 15/10/24.
// Copyright © 2015年 shen. All rights reserved.
// import UIKit class ViewController: UIViewController { var popView:UIView!
var clkbtn:UIButton!=UIButton()
var display:Bool=false override func viewDidLoad() {
super.viewDidLoad()
popView=UIView();
popView.frame=CGRectMake(,self.view.frame.size.height, self.view.frame.size.width, );
popView.backgroundColor=UIColor.redColor();
self.view.addSubview(popView); clkbtn=UIButton();
clkbtn.frame=CGRectMake(self.view.frame.size.width/-, self.view.frame.size.height/-, , );
clkbtn.setTitle("弹出", forState: UIControlState.Normal);
clkbtn.backgroundColor=UIColor.grayColor();
clkbtn.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside);
self.view.addSubview(clkbtn); } override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} func buttonClicked(sender:UIButton)
{
if(display==false){
display=true;
clkbtn.setTitle("隐藏", forState: UIControlState.Normal);
UIView.animateWithDuration(0.5, animations: {
self.popView.frame=CGRectMake(,self.view.frame.size.height-, self.view.frame.size.width, );
}, completion: nil);
}else{
display=false;
clkbtn.setTitle("弹出", forState: UIControlState.Normal);
UIView.animateWithDuration(0.5, animations: {
self.popView.frame=CGRectMake(,self.view.frame.size.height, self.view.frame.size.width, );
}, completion: nil);
}
}
}

demo地址: https://github.com/rayshen/SwiftAnimationTest
iOS Swift最简单的Animation的更多相关文章
- ios swift 实现简单MVP模式
在移动开发中,会用到各种架构,比如mvp,mvvm等,其目的就是为了让项目代码的可读性更好,减轻在android(activity) ios(controller)中的大量代码问题.接下来就开始我们的 ...
- iOS开发Swift篇—简单介绍
iOS开发Swift篇—简单介绍 一.简介 Swift是苹果于2014年WWDC(苹果开发者大会)发布的全新编程语言 Swift在天朝译为“雨燕”,是它的LOGO 是一只燕子,跟Objective-C ...
- ios swift 实现饼状图进度条,swift环形进度条
ios swift 实现饼状图进度条 // // ProgressControl.swift // L02MyProgressControl // // Created by plter on 7/2 ...
- 如何使用 Swift 开发简单的条形码检测器?
[编者按]本文作者为 Matthew Maher,主要手把手地介绍如何用 Swift 构建简单的条形码检测器.文章系 OneAPM 工程师编译整理. 超市收银员对货物进行扫码,机场内录入行李或检查乘客 ...
- ios下最简单的正则,RegexKitLite
ios下最简单的正则,RegexKitLite 1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中.备用地址:http://www.coco ...
- iOS中XMPP简单聊天实现 好友和聊天
版权声明本文由陈怀哲首发自简书:http://www.jianshu.com/users/9f2e536b78fd/latest_articles;微信公众号:陈怀哲(chenhuaizhe2016) ...
- iOS swift的xcworkspace多项目管理(架构思想)
iOS swift的xcworkspace多项目管理(架构思想) 技术说明: 今天在这里分享 swift下的 xcworkspace多项目管理(架构思想),能为我们在开发中带来哪些便捷?能为我们对整 ...
- iOS Swift 模块练习/swift基础学习
SWIFT项目练习 SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图 +控件 1.UIImag ...
- Building gRPC Client iOS Swift Note Taking App
gRPC is an universal remote procedure call framework developed by Google that has been gaining inter ...
随机推荐
- perl 下使用非root用户安装模块
perl下安装模块可以使用cpan命令,但是通常我们不具有root用户权限,所以只能以sudo方式安装模块. 例如需要安装Net::SCP::Expect模块, 执行cpan Net::SCP::Ex ...
- Hibernate大福利 下载链接
正在学马士兵Hibernate的同学来看这里,这里提供了他视频里需要的JAR包,请尽情下载,给好评喔. 一.Hibernate 3.3.2 核心JAR包 http://pan.baidu.com/s/ ...
- 线程本地变量ThreadLocal源码解读
一.ThreadLocal基础知识 原始线程现状: 按照传统经验,如果某个对象是非线程安全的,在多线程环境下,对对象的访问必须采用synchronized进行线程同步.但是Spring中的各种模板 ...
- Xen
Xen是一个开放源代码虚拟机监视器,由剑桥大学开发.它打算在单个计算机上运行多达128个有完全功能的操作系统. 在旧(无虚拟硬件)的处理器上执行Xen,操作系统必须进行显式地修改(“移植”)以在Xen ...
- 边界网关协议BGP
Border Gateway Protocol (BGP) is a standardized exterior gateway protocol designed to exchange routi ...
- 数据库MongoDB查询语句--持续更新
模糊查询: 包含字符串str : find({'name':/str/i}); {'name':/str/} 以str开头: {'name':/^str/} $in查询: 字段:{ field: ...
- scrollHeight,scrollLeft,offsetHeight,offsetLeft
scrollHeight:内部元素的绝对高度,包含内部元素的隐藏的部分scrollWidth:内部元素的绝对宽度,包含内部元素的隐藏的部分 scrollLeft:设置或获取位于对象左边界和窗口中目前可 ...
- linux初级,连网
第一次写,今天刚好装上centos,然后就玩装一些软件,但要联网,所以琢磨了半天连网,下面总结下今天积累的一些知识点吧! 首先需要查看电脑有没有装驱动:ifconfig -a, 看有没有eh0(网卡) ...
- Hibernate 的dialect 大全
RDBMS 方言 DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS3 ...
- linux 下第一个cordova android app
上篇博客写了linux下 cordova + ionic 环境的搭建 , 今天就来做下第一个app的简单讲解吧 首先昨天已经可以通过命令行的方式创建app了.经过今天好一段时间的研究发现使用 ioni ...