Swift에서 CATransform3D를 사용하는 경우

6265 단어 CATransform3DSwift
나는 막 해 보려고 했는데 곧 몰라서 필기를 대신했다.

회색으로 살짝 두드리면 회색으로 된 부분이 왔다 갔다 합니다.그거밖에 없어요.
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
        }
    }
}

좋은 웹페이지 즐겨찾기