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

  • 相关阅读:
    恐怖的东西,C#进入前四,进入正轨。
    JavaScript高级培训-自定义对象
    优秀程序员无他善假于物也
    Java基础知识之泛型全接触
    Haskell函数式编程之二递归
    敏捷的写博客
    生命、宇宙及万物的终极答案《图灵的秘密》读后感
    Java基础知识之Enum全接触
    WebDriver自动化测试利器剖析
    Haskell函数式编程之三纯函数式编程特点
  • 原文地址:https://www.cnblogs.com/wangdelong/p/3848537.html
Copyright © 2011-2022 走看看