//

// ViewController.swift

// UILabelTest

//

// Created by mac on 15/6/23.

// Copyright (c) 2015年 fangyuhao. All rights reserved.

//

import UIKit

import CoreMotion

class ViewController: UIViewController{

var rect:UIView!

override func viewDidLoad() {
super.viewDidLoad()
//1滑动手势
var swipe = UISwipeGestureRecognizer(target: self, action: Selector("swipe"))//默认右滑触发
swipe.direction = UISwipeGestureRecognizerDirection.Up
self.view.addGestureRecognizer(swipe)
//2轻点
var tapSingle = UITapGestureRecognizer(target: self, action: Selector("tapSingleDid"))
tapSingle.numberOfTapsRequired = 1
tapSingle.numberOfTouchesRequired = 1
var tapDouble = UITapGestureRecognizer(target: self, action: Selector("tapDoubleDid"))
tapDouble.numberOfTapsRequired = 2
tapDouble.numberOfTouchesRequired = 1
//声明点击事件需要双击事件检测失败后才会执行
tapSingle.requireGestureRecognizerToFail(tapDouble)
self.view.addGestureRecognizer(tapSingle)
self.view.addGestureRecognizer(tapDouble)
//3捏合手势
var pinch = UIPinchGestureRecognizer(target: self, action: Selector("pinchDid"))
self.view.addGestureRecognizer(pinch)
//旋转
var rotation = UIRotationGestureRecognizer(target: self, action: Selector("rotationDid"))
self.view.addGestureRecognizer(rotation)
//拖动
rect = UIView(frame: CGRectMake(0, 0, 100, 100))
rect.center = self.view.center
rect.backgroundColor = UIColor.redColor()
self.view.addSubview(rect)
var pan = UIPanGestureRecognizer(target: self, action: Selector("panDid:"))
pan.maximumNumberOfTouches = 1
rect.addGestureRecognizer(pan)
// Do any additional setup after loading the view, typically from a nib.
}
func swipe(){
println("swipe ok")
}
func tapSingleDid(){
println("tapSingleDid ok")
}
func tapDoubleDid(){
println("tapDoubleDid ok")
}
func pinchDid(){
println("pinchDid ok")
}
func rotationDid(){
println("rotationDid ok")
}
func panDid(recognizer:UISwipeGestureRecognizer){
var point = recognizer.locationInView(self.view)
rect.center = point
}

}

04-14 03:23