//
//  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. kafka速度为什么快

    1. kafka 使用了 分区.分布式.leader/followere 的方式.分布式让 kafka 排除了单点故障,分区和分区复制让数据不丢失2. kafka 使用 zero copy 技术 (基 ...

  2. spring 配置文件中使用properties文件 配置

    配置Bean载入properties文件: <bean id="propertyPlaceholderConfigurer" class="org.springfr ...

  3. jeecg中的树形控件demo

    1.comboTree控件 1.页面方法: <t:comboTree url="jeecgFormDemoController.do?getComboTreeData" va ...

  4. Hive 查看日志

    日志记录了程序运行的过程,是一种查找问题的利器. Hive中的日志分为两种1. 系统日志,记录了hive的运行情况,错误状况.2. Job 日志,记录了Hive 中job的执行的历史过程. 系统日志存 ...

  5. pythonNet08

    线程通信 通信方法:多个线程共用进程空间,所以进程的全局变量对进程内线程均可见.线程往往使用全局变量进行通信 注意事项:线程间使用全局变量进行通信,全局变量为共享资源,往往需要同步互斥机制 线程的同步 ...

  6. Linux安装Python虚拟环境virtualenv

    1.安装virtulenv.virtulenvwrapper包 pip install virtualenv virtualenvwrapper 2.virtualenvwrapper是virtual ...

  7. python一些不错的东西

    1 cmd命令行写代码的加强版  ipython  直接用pip安装就可以   php install Ipython 2 不错的数据分析 机器语言的 Python(x,y)是一个基于python的科 ...

  8. OpenCV学习笔记 - Video Analysis - 录制视频

    录制视频 使用自带摄像头录制一段5s的短视频 error & solution fourcc1 = cv2.CV_FOURCC(', 'v') 在实践过程中,运行这一行时报错: 原因分析 在o ...

  9. MVC各层的职责

    Model(模型):模型代表着核心的业务逻辑和数据(不要理解成Model只是实体类) View(视图):视图应该关注与如何展示数据,而不应该包含任何业务逻辑(业务逻辑应写在Model中) Contro ...

  10. Python运维开发基础05-语法基础

    上节作业回顾(讲解+温习90分钟) #!/usr/bin/env python # -*- coding:utf-8 -*- # author:Mr.chen import os,time Tag = ...