Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Learn Gesture
- //
- // Created by Thieu Mao on 12/17/16.
- // Copyright © 2016 thieumao. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var myImage: UIImageView!
- override func viewDidLoad() {
- super.viewDidLoad()
- let rotate = UIRotationGestureRecognizer(target: self, action: #selector(self.rotationAction(sender:)))
- self.myImage.addGestureRecognizer(rotate)
- }
- @IBAction func rotationAction(sender: UIRotationGestureRecognizer) {
- print("Rotation")
- sender.view!.transform = sender.view!.transform.rotated(by: sender.rotation)
- sender.rotation = 0
- /*
- Trong 2 dòng code trên, dòng code thứ nhất để set cho sender.view (trường hợp này chính là imageView) xoay theo ngón tay của user (2 ngón); dòng code thứ hai để set giá trị rotation của sender về 0, nếu không có dòng này thì image view của chúng ta sẽ xoay với góc xoay rất lớn so với góc xoay của 2 ngón tay user.
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment