• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

swift中手势的使用

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

swift 中手势的使用

/**点击手势*/

func tapGestureDemo() {

    //建立手势识别器

    let gesture = UITapGestureRecognizer(target: self, action: "viewTap:")

    //附加识别器到视图

    self.view1.addGestureRecognizer(gesture)

}

 

/**缩放手势*/

func pinchGestureDemo() {

    //建立手势识别器

    let gesture = UIPinchGestureRecognizer(target: self, action: "viewPinch:")

    //附加识别器到视图

    self.view1.addGestureRecognizer(gesture)

}

 

/**旋转手势*/

func rotationGestureDemo() {

    //建立手势识别器

    let gesture = UIRotationGestureRecognizer(target: self, action: "viewRotation:")

    //附加识别器到视图

    self.view1.addGestureRecognizer(gesture)

}

 

/**滑动手势*/

func swipeGestureDemo() {

    //建立手势识别器

    let gesture = UISwipeGestureRecognizer(target: self, action: "viewSwipe:")

    //附加识别器到视图

    self.view1.addGestureRecognizer(gesture)

}

 

/**平移手势*/

func panGestureDemo() {

    //建立手势识别器

    let gesture = UIPanGestureRecognizer(target: self, action: "viewPan:")

    //附加识别器到视图

    self.view1.addGestureRecognizer(gesture)

}

 

/**长按手势*/

func LongPressGestureDemo() {

    //建立手势识别器

    let gesture = UILongPressGestureRecognizer(target: self, action: "viewLongPress:")

    //附加识别器到视图

    self.view1.addGestureRecognizer(gesture)

}

 

/**自定义手势*/

func custonGestureDemo() {

    //建立手势识别器

    let gesture = CustomGestureRecognizer(target: self, action: "viewCustom:")

    //附加识别器到视图

    self.view1.addGestureRecognizer(gesture)

}

 

//-----------------------手势action事件---------------------------

/**点击事件*/

@IBAction func viewTap(sender: UITapGestureRecognizer) {

    print("clicked...")

}

 

/**缩放事件*/

func viewPinch(sender: UIPinchGestureRecognizer) {

    print("pinch...")

    let _width = view1.bounds.width

    let _height = view1.bounds.height

    view1.bounds.size = CGSize(width: _width * sender.scale, height: _height * sender.scale)

}

 

/**旋转事件*/

func viewRotation(sender: UIRotationGestureRecognizer) {

    view1.transform = CGAffineTransformMakeRotation(sender.rotation)

}

 

/**滑动事件*/

var offsetX: CGFloat = 0

func viewSwipe(sender: UISwipeGestureRecognizer) {

    if sender.direction == UISwipeGestureRecognizerDirection.Right {

        //每次向右平移20

        offsetX += 20

        view1.transform = CGAffineTransformMakeTranslation(offsetX, 0)

    }

}

 

/**平移事件*/

func viewPan(sender: UIPanGestureRecognizer) {

    let _transX = sender.translationInView(view1).x

    let _transY = sender.translationInView(view1).y

 

    view1.transform = CGAffineTransformMakeTranslation(_transX, _transY)

}

 

/**长按事件*/

func viewLongPress(sender: UILongPressGestureRecognizer) {

    print("long pressed....")

}

 

func viewCustom(sender: CustomGestureRecognizer) {

    print("custom gesture...")

}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[Swift]LeetCode473.火柴拼正方形|MatchstickstoSquare发布时间:2022-07-13
下一篇:
swift计算label动态宽度和高度发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap