//
//  ViewController.swift
//  MapAnimation
//
//  Created by su on 15/12/10.
//  Copyright © 2015年 tian. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
   
    var appBackGround:UIImageView!
    var mapView: UIImageView!
    var mapShowing:Bool = false
   
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.blackColor()
        //构建第一视图
        appBackGround = UIImageView(frame: CGRectMake(0, 64, self.view.frame.size.width,458))
        appBackGround.image = UIImage(named: "app-bg")
        self.view.addSubview(appBackGround)
       
        //构建地图视图
        mapView = UIImageView(frame: CGRectMake(0, 132, self.view.frame.size.width,458))
        mapView.image = UIImage(named: "map-arrow")
        mapView.alpha = 0
        CGAffineTransformScale(mapView.transform, 1.1, 1.1)
        self.view.addSubview(mapView)
       
        //构建执行动画的button
        let right = UIBarButtonItem(image: UIImage(named: "map-icon"), style: UIBarButtonItemStyle.Plain, target: self, action: "right")
        self.navigationItem.rightBarButtonItem = right
       
       
    }
    func right() {
        //显示地图的阻尼值是16 隐藏地图的阻尼值24
        let damplingStiffness:CGFloat = 8.0
        let daplingStiffnessOut:CGFloat = 12
       
        if mapShowing {
            mapShowing = false
            //隐藏地图
            UIView.animateWithDuration(0.1, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                self.appBackGround.alpha = 1
                }, completion: nil)
           
            let jnw缩放 = JNWSpringAnimation(keyPath: "transform.scale")
            jnw缩放.damping = damplingStiffness
            jnw缩放.stiffness = damplingStiffness
            jnw缩放.mass = 1
            //将尺寸从0.9 还原成1
            jnw缩放.fromValue = 0.9
            jnw缩放.toValue = 1
            appBackGround.layer.addAnimation(jnw缩放, forKey: jnw缩放.keyPath)
            appBackGround.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0)
           
            //地图视图的动画代码
           
            UIView.animateWithDuration(0.1, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                self.mapView.alpha = 0
                }, completion: nil)
           
            let jnw地图缩放 = JNWSpringAnimation(keyPath: "transform.scale")
            jnw地图缩放.damping = daplingStiffnessOut
            jnw地图缩放.stiffness = daplingStiffnessOut
            jnw地图缩放.mass = 1
            jnw地图缩放.fromValue = 1.1
            jnw地图缩放.toValue = 1
            self.mapView.layer.addAnimation(jnw地图缩放, forKey: jnw地图缩放.keyPath)
            self.mapView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1)
            //位移jnw对象
            let jnw地图下移 = JNWSpringAnimation(keyPath: "transform.translation.y")
            jnw地图下移.damping = daplingStiffnessOut
            jnw地图下移.stiffness = daplingStiffnessOut
            jnw地图下移.mass = 1
            jnw地图下移.fromValue = 0
            jnw地图下移.toValue = 30
            self.mapView.layer.addAnimation(jnw地图下移, forKey: jnw地图下移.keyPath)
            self.mapView.transform = CGAffineTransformTranslate(self.mapView.transform, 0, 0)
           
           
        } else {
            //显示地图
            mapShowing = true
            //第一视图的动画代码
            UIView.animateWithDuration(0.1, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                self.appBackGround.alpha = 0.3
                }, completion: nil)
            let scale = JNWSpringAnimation(keyPath: "transform.scale")
            scale.damping = damplingStiffness
            scale.stiffness = damplingStiffness
            scale.mass = 1
            //初始值取得当前背景的缩放值
            scale.fromValue = 1
            scale.toValue = 0.9
            self.appBackGround.layer.addAnimation(scale, forKey: scale.keyPath)
            self.appBackGround.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9)
 
           
            //地图动画代码
            UIView.animateWithDuration(0.1, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                self.mapView.alpha = 1
                }, completion: nil)
            //利用jnw框架组合两个动画
            let mapScale = JNWSpringAnimation(keyPath: "transform.scale")
            mapScale.damping = daplingStiffnessOut
            mapScale.stiffness = daplingStiffnessOut
            mapScale.mass = 1
            mapScale.fromValue = 1
            mapScale.toValue = 1.1
            self.mapView.layer.addAnimation(mapScale, forKey: mapScale.keyPath)
            self.mapView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1)
            //位移动画
            let mapTranslate = JNWSpringAnimation(keyPath: "transform.translation.y")
            mapTranslate.damping = daplingStiffnessOut
            mapTranslate.stiffness = daplingStiffnessOut
            mapTranslate.mass = 1
            mapTranslate.fromValue = 30
            mapTranslate.toValue = 0
            self.mapView.layer.addAnimation(mapTranslate, forKey: mapTranslate.keyPath)
            self.mapView.transform = CGAffineTransformTranslate(self.mapView.transform, 0, 0)
           
           
        }
    }

override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

 

swift - 动画学习的更多相关文章

  1. Swift 动画学习笔记

    视频地址: http://www.swiftv.cn/course/i275v5lz 1,动画属性 position(位置),opacity(透明度,0 全透明,1 不透明),Scale(尺寸),Co ...

  2. Android动画学习(二)——Tween Animation

    前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...

  3. 一份关于Swift语言学习资源的整理文件

    一份关于Swift语言学习资源的整理文件     周银辉 在这里下载 https://github.com/ipader/SwiftGuide

  4. Swift入门学习之一常量,变量和声明

    版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请表明出处:http://www.cnblogs.com/cavalier-/p/6059421.html Swift入门学习之一常量,变量和 ...

  5. Android动画学习笔记-Android Animation

    Android动画学习笔记-Android Animation   3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...

  6. OSG动画学习

    OSG动画学习 转自:http://bbs.osgchina.org/forum.php?mod=viewthread&tid=3899&_dsign=2587a6a9 学习动画,看了 ...

  7. android动画学习

    android动画学习   转载自:http://www.open-open.com/lib/view/open1329994048671.html 3.0以前,android支持两种动画模式,twe ...

  8. Swift开发学习(两):Playground

    Swift开发学习:Playground 大约 对于软件用户.游戏玩家,我一直提倡用户体验.也是用户,是各种开发工具的使用者.也会喜欢用户体验做得好的工具软件.这次苹果想开发人员所想,提供了一个能够玩 ...

  9. ios 动画学习的套路 (二)

    有它们俩你就够了! 说明:下面有些概念我说的不怎么详细,网上实在是太多了,说了我觉得也意义不大了!但链接都给大家了,可以自己去看,重点梳理学习写动画的一个过程和一些好的博客! (一) 说说这两个三方库 ...

随机推荐

  1. vim自定义配置之nerdTree

    vimConfig/plugin/nerdTree-setting.vim let g:NERDTree_title="[NERDTree]" nmap <F2> :N ...

  2. emacs之配置auto-complete

    el-get-install安装auto-complete emacsConfig/auto-complete-setting.el ;这个是设置一个字母就自动完成的 (setq ac-auto-st ...

  3. java web 程序---注册页面核心代码哈希Map

    收获:在运行程序的时候,错误出现.主要是map没有进行判断,是否为空,如果为空,则创建一个对象new HashMap(); 然后就注意细节, String name=request.getParame ...

  4. Java 从原字符串中截取一个新的字符串 subString()

    Java 手册 substring public String substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串.该子字符串从指定索引处的字符开始,直 ...

  5. eclipse+maven springMVC搭建

    1.新建项目: 选择Maven Project 选择项目位置,这里我选择的是C:\Users\admin\workspace\practice 选择maven项目类型,这里选择webapp: 填写Gr ...

  6. java中的DAO设计模式

    创建数据库和表 sql语句: DROP TABLE IF EXISTS product; CREATE TABLE product( product_id varchar(20) NOT NULL, ...

  7. android.support.v7.internal.widget.ActionBarOverlayLayout Couldn't Be Initialized

    问题症状: Android Studio 1.2 (Build 141.1890965) 新建工程,自动build完成后,Layout Editor无法预览Layout文件,报错内容: Renderi ...

  8. fadora24安装settools,pip包出错解决方法

    1.fadora24安装Python2.7 [root@dev ~]# python bash: python: 未找到命令... 安装软件包“python”以提供命令“python”? [N/y] ...

  9. 获取文件夹总大小方法2_获取cmd命令结果,效率最高

    public static long GetDirectorySize(string path) { long res = 0; System.Diagnostics.Process p = new ...

  10. 像素(PX)转其它长度单位(mm、cm...)

    今天想把px转成mm为单位,因像素跟其它单位比值的大小会跟屏幕设置的分辨率大小而不定,因此不能以固定的数值去计算. 解决方法是 页面上放一个高度为1mm的隐藏块 <div id="di ...