class MyView: UIView {

var lView:UIView!

var time:NSTimer!

override init(frame: CGRect) {

super.init(frame: frame)

//开启多点触控

self.multipleTouchEnabled = true

lView = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50));

lView.backgroundColor = UIColor.yellowColor();

self.addSubview(lView)

}

required init?(coder aDecoder: NSCoder) {

super.init(coder: aDecoder)

}

//开始点击时,调用的方法

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

//        println(count)

//拿到一个UITouch对象

//        let touch:UITouch = touches.anyObject() as! UITouch;

let touch = touches.first as UITouch!

//拿到点击次数

let tapCount = touch.tapCount;

if (tapCount == 1)

{

//  单击 singleTap()

//使用定时器延时调用

time = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector:"singleTap", userInfo: nil, repeats: false)

}else

{

//终止定时器

time.invalidate()

doubleTap()

}

}

func singleTap() {

print("单击")

}

func doubleTap() {

print("双击")

}

//触摸移动时,调用的方法

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

// var touch = touches.anyObject() as! UITouch

let touch = touches.first as UITouch!

let location = touch.locationInView(self)

// println("location: \(location.x), \(location.y), \(location)")

let lastLocation = touch.previousLocationInView(self)

// println("lastLocation: \(lastLocation.x), \(lastLocation.y), \(lastLocation)")

let sub = location.x - lastLocation.x

if sub > 0{

print("right")

}else if sub < 0 {

print("left")

}else {

print("move")

}

//让小矩形跟着手势移动  lView.center = location

lView.frame.origin = location

}

}

swift 触摸与手势的更多相关文章

  1. IOS 手势-轻点、触摸、手势、事件

    1.概念 手势是从你用一个或多个手指接触屏幕时开始,直到手指离开屏幕为止所发生的所有事件.无论手势持续多长时间,只要一个或多个手指仍在屏幕上,这个手势就存在. 触摸是指把手指放到IOS设备的屏幕上,从 ...

  2. JavaScript触摸与手势事件

    JavaScript触摸与手势事件 发表于 2012-12-10 由 admin iOS版Safari为了向开发人员传达一些特殊信息,新增了一些专有事件.因为iOS设备既没有鼠标也没有键盘,所以在为移 ...

  3. js监听事件 上滑消失下滑出现的效果 触摸与手势事件

    https://www.w3cmm.com/javascript/touch.html //触摸与手势事件连接tinyscrollbar //方法1var _this = $('#fabu');var ...

  4. Flex中处理多点触摸和手势

    在Flex中多点触摸和手势都需要利用Multitiouch类来完成:1.supportsGestureEvents:判断是否支持手势2.supportsTouchEvents:判断是否支持多点触摸可以 ...

  5. Javascript高级编程学习笔记(69)—— 事件(13)触摸与手势事件

    触摸与手势事件 由于移动设备既没有鼠标也没有键盘,所以在为移动浏览器开发交互性网页时,常规的鼠标键盘事件根本不够用 所以早期的苹果为Safari 添加了一些与触摸相关的事件 随着后面Android的W ...

  6. T470 Win10下触摸板手势

    T470 Win10下触摸板手势 学习了:https://forum.51nb.com/thread-1742490-1-1.html 三指横向竟然是alt+tab 学习了:http://www.xi ...

  7. 小米和MAC触摸板手势汇总

    小米的触摸手势: 左键:单指单击 右键:双指单击 选取并打开:单指双击 滚动页面:双指 移动 拖拽项目:双击并拖拽 放大/缩小:双指张开,双指捏合 MAC触摸板手势: http://www.cr173 ...

  8. 触摸与手势学习-swift

    触摸是一个UITouch对象,该对象放在一个UIEvent中,每个UIEvent包含一个或多个UITouch对象,每个UITouch对象对应一个手指.系统将UIEvent发送到应用程序上,最后应用程序 ...

  9. iOS之触摸及手势

    触摸事件 iOS中的事件: 在用户使用app过程中,会产生各种各样的事件.iOS中的事件可以分为3大类型:    view的触摸事件处理: 响应者对象: 在iOS中不是任何对象都能处理事件,只有继承了 ...

随机推荐

  1. glog安装与使用

    window环境下glog的安装 载后解压,利用Visual Studio打开google-glog.sln.生成解决方案 打开sln会有几个项目,libglog是动态库,生成dll,libglog_ ...

  2. 使用U盘安装linux系统

    1. 下载并安装:UltraISO.流氓软件太多,最后是在百度软件中心下的,推荐. 2. 插入U盘.打开UltraISO,然后:文件 -- 打开 -- 选择你的ISO文件,打开. 3. UltraIS ...

  3. RC1意思

    软件各种版本的表示 alpha 内部测试版 beta 外部测试版 demo 演示版 Enhance 增强版或者加强版 属于正式版 Free 自由版 Full version 完全版 属于正式版 sha ...

  4. Win7系统(台式机)设置系统的窗口背景色(豆沙绿色)

    Win7系统(台式机)设置系统的窗口背景色(豆沙绿色) 1,桌面->右键->个性化->窗口颜色->高级外观设置->项目选择(窗口).颜色1(L)选择(其它)将色调改为:8 ...

  5. linux及安全期中总结——20135227黄晓妍

    Linux及安全期中总结 黄晓妍 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ...

  6. Java,vue.js,jsp for循环的写法

    vue.js <li v-for="student in studentList">{{student.name}}</li> jsp el表达式 < ...

  7. 图像添加logo水印函数

    <?php //图像添加水印函数 /** *为一张图片添加上一个logo水印(以保存新图片的方式实现) *@param string $picname 被缩放的处理图片源 *@param int ...

  8. Codeforces Round #398 (Div. 2) A,B,C,D

    A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. CSS 再学习,文本处理

    文本缩进(对p,div有效:对span无效) p {text-indent: 5em;} Tips:一般来说,可以为所有块级元素应用 text-indent,但无法将该属性应用于行内元素(span), ...

  10. python2和python3的区别——持续更新

    1.在 cookbook 上看到的,python3支持 *运算符 来接收迭代变量,如: a, *b = [, , , ] python2是不支持的! 2.在 cookbook 上看到的,python3 ...