23. 手势识别之UIRotationGestureRecognizer

来源:互联网 发布:黑客用函数语言编程 编辑:程序博客网 时间:2024/06/01 09:30

UIRotationGestureRecognizer

旋转手势,使用和前面的非常类似, 我们学习如何使用它

1. UIRotationGestureRecognizer的创建

下面我们来使用它实现一个图片随手势旋转

import UIKitclass ViewController: UIViewController {    var imageView: UIImageView!    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view.        self.imageView = UIImageView(image: UIImage(named: "thumbHighlighted"))        self.imageView.center = self.view.center        self.view.addSubview(self.imageView)        let rotationGestureRecognizer = UIRotationGestureRecognizer(target: self, action: "rotationAction:")        self.view.addGestureRecognizer(rotationGestureRecognizer)    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }    func rotationAction(rotationGestureRecognizer: UIRotationGestureRecognizer) {        self.imageView.transform = CGAffineTransformMakeRotation(rotationGestureRecognizer.rotation)    }}

运行程序:
创建

2. UIRotationGestureRecognizer详解

我们查看它的定义

@available(iOS 3.2, *)public class UIRotationGestureRecognizer : UIGestureRecognizer {    // 旋转弧度    public var rotation: CGFloat    // 旋转速度    public var velocity: CGFloat { get } }

它的属性也就两个: 旋转角度和旋转弧度.

3. 完整代码

同第一部分

1 0
原创粉丝点击