ちょっと試してみようと思ったらすぐには分からなかったのでメモ代わりに。
灰色の箇所をタップすると灰色の部分がくるりと回ります。それだけ。
ViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let view : UIView = UIView(frame: CGRectMake(100, 100, 100, 100))
view.backgroundColor = UIColor.grayColor()
view.userInteractionEnabled = true
view.tag = 1
self.view.addSubview(view)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
let touche : UITouch = touches.anyObject() as UITouch
switch (touche.view.tag as Int) {
case 1:
let animation : CABasicAnimation = CABasicAnimation(keyPath: "transform")
animation.duration = 0.5
animation.repeatCount = 1
animation.autoreverses = true
let transform : CATransform3D = CATransform3DMakeRotation(CGFloat(M_PI), 1.0, 0.5, 0.0)
animation.toValue = NSValue(CATransform3D : transform)
touche.view.layer.addAnimation(animation, forKey: "transform")
default:
break
}
}
}