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为点击视图时记录的视图位置点,加上平移的像素,就会得出视图的中心点的偏移量

  • 相关阅读:
    [Design]设计模式结构模式
    [Design] 设计模式行为模式
    [Design] Decorator Pattern
    ILIST<T>和LIST<T> 枫
    js 如何调用Windows自带的配色控件 枫
    WML语法全接触 WAP建站语言 枫
    Asp.net模板引擎技术 枫
    smarty内建函数 枫
    NameValueCollection详解 枫
    smarty循环调用问题 枫
  • 原文地址:https://www.cnblogs.com/oscar1987121/p/5665278.html
Copyright © 2011-2022 走看看