zoukankan      html  css  js  c++  java
  • 手势(3)view随手势移动

    #import "QYCustomView.h"

    /*
    #define  HOR_SWIPE_MIN 20 //水平上,当低于这个值的时候, 不认为他是一个横扫的手势
    #define  VAR_SWIPE_MAX 40 //在垂直上,设置这误差范围,如果大于这个值的话, 横扫无效
     */

    @implementation QYCustomView

    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
        if (self) {
            self.backgroundColor = [UIColor purpleColor];
            _moveView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 30, 30)];
            _moveView.backgroundColor = [UIColor redColor];
            [self addSubview:_moveView];
        }
        return self;
    }

    //当我们的事件开始的时候调, 对于touch来说, 实际上当手指头放到屏幕上的时候,这个方法会被调用
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        _moveView = [[UIView alloc ]initWithFrame:CGRectMake(0, 0, 30, 30)];
        _moveView.backgroundColor = [UIColor redColor];
        [self addSubview:_moveView];
    }



    ////当我们手指点击屏幕,并且没有抬起而滑动的时候, 这个方法被调用, 由此可知这个方法是连续被调用的。
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *tch = [touches anyObject];
        CGPoint currentPoint = [tch locationInView:self];
        
    //    CGRect frame = self.moveView.frame;
        self.moveView.center = currentPoint;
        
        NSLog(@"%s",__func__);
    }



    //当我们的事件对束的时候调,对于touch来说, 实际上是当手指头离开屏幕的时候,这个方法会被调用
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {

    }

    /*
    //
    ////当我们的事件被取消的时候, 比如说:手指点击在屏幕上, 突然来电话, 这个时候, 电话的优先级很高,
    ////所有的事件都应该被取消。 这个方法会被调用
    //- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    //{
    //    NSLog(@"%s",__func__);
    //    self.startPoint = CGPointZero;
    //}
    */

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
        self.backgroundColor = [UIColor orangeColor];
    }
     */
    @end

  • 相关阅读:
    go微服务框架kratos学习笔记十(熔断器)
    go微服务框架kratos学习笔记九(kratos 全链路追踪 zipkin)
    go微服务框架kratos学习笔记八 (kratos的依赖注入)
    go微服务框架kratos学习笔记七(kratos warden 负载均衡 balancer)
    编译原理之语法分析-自下而上分析(四)
    编译原理之语法分析-自下而上分析(三)
    编译原理之语法分析-自下而上分析(二)
    编译原理之语法分析-自下而上分析(一)
    TreeSet的两种实现方法:Comparable和Comparator(Java比较器)
    JavaWeb学习之JSP(三) EL表达式
  • 原文地址:https://www.cnblogs.com/wangdelong/p/3848537.html
Copyright © 2011-2022 走看看