• 手势(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

  • 相关阅读:
    徒手用Java来写个Web服务器和框架吧<第二章:Request和Response>
    徒手用Java来写个Web服务器和框架吧<第一章:NIO篇>
    Linux使用小笔记<进程操作篇>
    shell条件判断
    rz和sz上传下载文件
    vim 快捷键
    while read读取文本内容
    云主机启动提示Booting from Hard Disk GRUB
    centos7进入单用户模式
    账号被锁无法ssh登陆
  • 原文地址:https://www.cnblogs.com/wangdelong/p/3848537.html
Copyright © 2020-2023  润新知