//
// ViewController.swift
// 动画总结
//
// Created by admin on 16/1/29.
// Copyright © 2016年 jin. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// 控件的center和控件layer的position是默认相等的
print(self.image.center)
// anchorPoint相对于上级layer的坐标,注意anchorPoint和position的互相影响
print(self.image.layer.position)
print(self.image.layer.anchorPoint)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.animationD()
}
// 核心动画,需要知道的事,动画改编的position是假象,其实值并没有改变,只是看上去变了
func animationD()
{
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 3
animation.delegate = self
self.image.layer.position = CGPointMake(100, 100)
print("开始时的position")
print(self.image.layer.position)
self.image.layer.addAnimation(animation, forKey: nil)
}
override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
print("结束时的position")
print(self.image.layer.position)
}
// 这个好。。
func animationC()
{
UIView.transitionWithView(self.image, duration: 3, options: UIViewAnimationOptions.TransitionCurlDown, animations: {
self.image.image = UIImage(imageLiteral: "2")
}, completion: {
_ in
print("动画执行完成")
})
}
//
func animationB()
{
UIView.animateWithDuration(3, animations: {
// 切换图片没有动态
self.image.center = CGPointMake(100, 100)
})
}
// UIView动画
func animationA()
{
UIView.beginAnimations(nil, context: nil)
// 设置事件
UIView.setAnimationDuration(3)
// 设置代理
UIView.setAnimationDelegate(self)
UIView.setAnimationDidStopSelector("stop")
// 实现动画代码,切换图片没有效果。。。
self.image.center = CGPointMake(100, 100)
UIView.commitAnimations()
}
func stop()
{
print("动画结束啦")
}
}