10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftでCATransform3Dを使う場合

Posted at

ちょっと試してみようと思ったらすぐには分からなかったのでメモ代わりに。

スクリーンショット 2014-09-15 01.04.35.png

灰色の箇所をタップすると灰色の部分がくるりと回ります。それだけ。

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
        }
    }
}

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?