zoukankan      html  css  js  c++  java
  • IOS开发之进阶篇第一章

    今天讲一下姿势识别器,UIGestureRecognizer这个是抽象类

      1、拍击UITapGestureRecognizer (任意次数的拍击)  

      2、向里或向外捏UIPinchGestureRecognizer (用于缩放)  

      3、摇动或者拖拽UIPanGestureRecognizer (拖动) 

      4、擦碰UISwipeGestureRecognizer (以任意方向)  

      5、旋转UIRotationGestureRecognizer (手指朝相反方向移动)  

      6、长按UILongPressGestureRecognizer (长按)

    基本用法是

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    

      然后定义它的回调方法handlePan:,每当用户在屏幕对对象进行相应的姿势进行操作的时候,都会触发回调方法

    -(void)handlePan:(UIPanGestureRecognizer *) recognizer
    {
        CGPoint translatedPoint = [recognizer translationInView:self.superview];
        
        self.center = CGPointMake(previousLocation.x+translatedPoint.x, previousLocation.y+translatedPoint.y);
    }
    

      回调方法中会有UIPanGestureRecognizer对应的识别器,识别器可以计算出在对应视图中的操作像素,如上面的代码,translationInView就是计算出在父视图中,的平移想像素

    并重新设置视图的中心点,previousLocation为点击视图时记录的视图位置点,加上平移的像素,就会得出视图的中心点的偏移量

  • 相关阅读:
    Hadoop 源码编译
    Hadoop之HDFS介绍
    CentOS 7 导入epel库
    CentOS7安装 VirtualBox虚拟机
    ios开发在导入环信SDK后运行出现 Reason: image not found 的解决方案
    centos安装PHP
    centOS安装apache服务器
    centOS最小化安装后网络连接问题
    django orm
    yield, async
  • 原文地址:https://www.cnblogs.com/oscar1987121/p/5665278.html
Copyright © 2011-2022 走看看