首页 > 学院 > 开发设计 > 正文

swift 拖动view代码

2019-11-08 19:52:31
字体:
来源:转载
供稿:网友

将一个View拖动到SB,创建一个redView继承自UIView,

//// RedView.swift// DragView//// Created by luoriver on 2017/2/15.// Copyright © 2017年 SocererGroup. All rights reserved.//import UIKitclass RedView: UIView { /* // Only override draw() if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func draw(_ rect: CGRect) { // Drawing code } */ override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { //获取手指 let touch = (touches as NSSet).anyObject() as! UITouch let nowLocation = touch.location(in: self) let PReLocation = touch.previousLocation(in: self) //获取两个手指的偏移量 let offsetX = nowLocation.x - preLocation.x let offsetY = nowLocation.y - preLocation.y var center = self.center center.x += offsetX center.y += offsetY self.center = center }}
上一篇:map与set

下一篇:GDOI2017模拟2.15

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表