19장 핀치 제스처 사용해 사진 확대/축소하기




//

//  ViewController.swift

//  PinchGesture

//

//  Created by stayfoolish on 24/10/2018.

//  Copyright © 2018 stayfoolish. All rights reserved.

//


import UIKit


class ViewController: UIViewController {


//    @IBOutlet var txtPinch: UILabel!

    @IBOutlet var imgPinch: UIImageView!

    

    var initialFontSize:CGFloat!

    

    override func viewDidLoad() {

        

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        let pinch = UIPinchGestureRecognizer(target: self, action: #selector(ViewController.doPinch(_:)))

        self.view.addGestureRecognizer(pinch)

    }


    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

    @objc func doPinch(_ pinch: UIPinchGestureRecognizer){

        /* label 확대 축소

        if (pinch.state == UIGestureRecognizerState.began){

            initialFontSize = txtPinch.font.pointSize

        }else {

            txtPinch.font = txtPinch.font.withSize(initialFontSize * pinch.scale)

        }

        */

        

        imgPinch.transform = imgPinch.transform.scaledBy(x: pinch.scale, y: pinch.scale)

        pinch.scale = 1

    }



}







+ Recent posts