zoukankan      html  css  js  c++  java
  • IOS添加手势识别

    ios里面有手势识别,多点触控等功能,过去要实现手势识别很复杂,现在苹果为我们实现了,手势识别变得很简单

    1.向视图添加手势识别器;(一般由controller完成,有时View也可以添加)

    2.提供一个方法去处理。

    ios开发添加手势识别有两种方法:

    一、代码添加手势识别

    通过代码添加手势识别:

    1.在controller里面向View添加手势识别并让View响应实现

    UISwipeGestureRecognizer * swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self.playingCardView action:@selector(swipe:)];
    [self.view addGestureRecognizer: swipe];

    上面的代码中UISwipeGestureRecognizer是UIGestureRecognizer抽象类的具体子类,initWithTarget:的参数是一个自定义的View,里面实现了方法 swipe:

    当手势被识别出来后,self.playingCardView就会调用swipe:

    2.在controller里面向View添加手势识别并让controller响应实现

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self.playingCardView addGestureRecognizer:tap];

    initWithTarget:的参数是self 也就是controller,当手势识别出来后由controller处理,controller提供一个处理的方法 tap:

    两个例子的不同地方还在于添加手势识别的视图不同,给self.view和self.playingCardView添加,只有在view或者playingCardView的区域(frame)内做出手势才会被识别。

    二、通过xode的界面编辑直接添加

    1.从storyboard里面拖拽要识别的手势到想要添加手势识别的view上

    2.再把添加的手势识别器连接到代码里面去

  • 相关阅读:
    Linux 常用命令--来自B站Up主codesheep
    如何区别调用python2和python3
    fastp 使用
    使用bash shell删除目录中的特定文件的3种方法
    python 正则表达式 finditer
    vcf format
    vcf文件(call variants得来的)怎么看变异是纯合还是杂合
    js Object.preventExtensions()
    js 对象的属性特征
    shell基础 以及 sed、awk
  • 原文地址:https://www.cnblogs.com/panxiaochun/p/5069482.html
Copyright © 2011-2022 走看看