最近发现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的更多相关文章

  1. ios swift 实现简单MVP模式

    在移动开发中,会用到各种架构,比如mvp,mvvm等,其目的就是为了让项目代码的可读性更好,减轻在android(activity) ios(controller)中的大量代码问题.接下来就开始我们的 ...

  2. iOS开发Swift篇—简单介绍

    iOS开发Swift篇—简单介绍 一.简介 Swift是苹果于2014年WWDC(苹果开发者大会)发布的全新编程语言 Swift在天朝译为“雨燕”,是它的LOGO 是一只燕子,跟Objective-C ...

  3. ios swift 实现饼状图进度条,swift环形进度条

    ios swift 实现饼状图进度条 // // ProgressControl.swift // L02MyProgressControl // // Created by plter on 7/2 ...

  4. 如何使用 Swift 开发简单的条形码检测器?

    [编者按]本文作者为 Matthew Maher,主要手把手地介绍如何用 Swift 构建简单的条形码检测器.文章系 OneAPM 工程师编译整理. 超市收银员对货物进行扫码,机场内录入行李或检查乘客 ...

  5. ios下最简单的正则,RegexKitLite

    ios下最简单的正则,RegexKitLite 1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中.备用地址:http://www.coco ...

  6. iOS中XMPP简单聊天实现 好友和聊天

    版权声明本文由陈怀哲首发自简书:http://www.jianshu.com/users/9f2e536b78fd/latest_articles;微信公众号:陈怀哲(chenhuaizhe2016) ...

  7. iOS swift的xcworkspace多项目管理(架构思想)

    iOS  swift的xcworkspace多项目管理(架构思想) 技术说明: 今天在这里分享 swift下的 xcworkspace多项目管理(架构思想),能为我们在开发中带来哪些便捷?能为我们对整 ...

  8. iOS Swift 模块练习/swift基础学习

    SWIFT项目练习     SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图  +控件 1.UIImag ...

  9. Building gRPC Client iOS Swift Note Taking App

    gRPC is an universal remote procedure call framework developed by Google that has been gaining inter ...

随机推荐

  1. jquery常用代码

    转自:未找到 以下是jquery中比较常用的一些操作实现方式: $("标签名") //取html元素 document.getElementsByTagName("&qu ...

  2. Caffe学习系列(2):数据层及参数

    要运行caffe,需要先创建一个模型(model),如比较常用的Lenet,Alex等, 而一个模型由多个屋(layer)构成,每一屋又由许多参数组成.所有的参数都定义在caffe.proto这个文件 ...

  3. 直流调速系统Modelica基本模型

    为了便于在OpenModelica进行仿真,形成一个完整的仿真模型,没有使用第三方的库,参照了DrModelica的例程,按照Modelica库的开源模型定义了所用的基本元件模型. 首先给出一些基本类 ...

  4. TensorFlow 源代码初读感受

    把自己微博发的文章:http://www.weibo.com/1804230372/En7PdlgLb?from=page_1005051804230372_profile&wvr=6& ...

  5. 基于Html5缓存的页面P2P技术可行性探讨

    P2P技术,在分享大文件(你懂的)是现在必不可缺的技术,现在的人,已经很难想象在没有这玩意的互联网早期,人们是怎样的艰难求生.想当年,不要说电影,下一个稍大点的文件,都是很吃力的事情. 后来牛人科恩, ...

  6. 备忘:maven 错误信息: Plugin execution not covered by lifecycle configuration

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  7. 20160220 - JavaScript for OS X Automation 调试技巧

    在JXA代码中加入如下代码后,可使用 Safari Web Inspector 调试: //debugger; 使用 Safari Web Inspector 查看 Array 或 Object 并不 ...

  8. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  9. oracle 学习笔记

    --2.2 进入和退出oracle数据库--在windows中输入cmd打开命令窗口 然后输入 sqlplu / as sysdba--验证数据库是否安装成功 --select status from ...

  10. 使用ContentProvider进行应用程序间的数据交互

    什么是ContentProvider: ContentProvider用来管理数据的访问规则.它允许你的应用程序向外界暴露需要被访问的数据. 是Android的四大组件之一. ContentProvi ...