最近几天看了老镇的动画的学习,有一部分是第三方库的应用,其便是JNWSpringAnimation的使用,首先是从github上下载这个包 在项目文件列表中创建new group 随后导入4个文件,因为是OC,所以要写桥接文件为
#import"JNWSpringAnimation"
随后在一个文件中加入一句话,忘了,
<img src="http://img.blog.csdn.net/20151020192935163?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<img src="http://img.blog.csdn.net/20151020193152237?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
第一张图是瞧见文件,第二张图是在某一个文件中加入这句improt<UIKit/UIKit.h>
明天在加<img alt="大笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif" />
下面便是在ViewController 中加入这段代码
<pre name="code" class="plain">// ViewController.swift
// shiyan28
//
// Created by HISE_CS on 15/10/10.
// Copyright 2015年 HISE_CS. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//设置红球 因为出来的是一个矩形,所以用圆角
let redBall = UIView(frame: CGRectMake(50, 50, 100, 100))
redBall.backgroundColor = UIColor.redColor()
self.view.addSubview(redBall)
//创建对象
let scale = JNWSpringAnimation(keyPath: "transform.translation.x")
//创建质量
scale.mass = 2
//设置阻尼值
scale.damping = 6
//弹性系数
scale.stiffness = 100
//设置初始值与结束值
scale.fromValue = 0
scale.toValue = 400
//添加到redball对象
redBall.layer.addAnimation(scale, forKey: scale.keyPath)
redBall.transform = CGAffineTransformMakeTranslation(400, 0)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
JNW中整体的东西还不是非常的了解,因此以后在学习,先把这段代码敲上吧