• 触发事件续


    Main.storyboard

    CZView.h

    #import <UIKit/UIKit.h>

     

    @interface CZView : UIView

     

    @end

    CZView.m

    //

    //  CZView.m

    //  6A05.触摸事件

    //

    //  Created by huan on 16/1/30.

    //  Copyright © 2016 huanxi. All rights reserved.

    //

     

    #import "CZView.h"

     

    @implementation CZView

     

    /*

    // Only override drawRect: if you perform custom drawing.

    // An empty implementation adversely affects performance during animation.

    - (void)drawRect:(CGRect)rect {

        // Drawing code

    }

    */

     

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

        return;

        NSLog(@"%s", __func__);

        //获取当前触摸点的UITouch对象

        UITouch *touch = [touches anyObject];

        //触摸的view

        NSLog(@"%@", touch.view);

        

        //tapCount 点击的次数

        NSLog(@"%ld", touch.tapCount);

        

        //获取当前 触摸的位置

    #warning 传一个nil 获取的触摸点的位置是在window上去  self = touch.view

        CGPoint touchPosition = [touch locationInView:self];

        NSLog(@"%@", NSStringFromCGPoint(touchPosition));

    }

     

    -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

        NSLog(@"%s", __func__);

        //获取当前触摸点的UITouch对象

        UITouch *touch = [touches anyObject];

        //获取当前触摸的位置

        CGPoint current = [touch locationInView:touch.view];

        //获取触摸前的位置

        CGPoint previous = [touch previousLocationInView:touch.view];

        NSLog(@"触摸前的点:%@ 当前触摸点:%@", NSStringFromCGPoint(previous), NSStringFromCGPoint(current));

        //改变位置

        CGPoint center = self.center;

        center.x += current.x - previous.x;

        center.y += current.y - previous.y;

        self.center = center;

    }

     

    -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

        NSLog(@"%s", __func__);

    }

     

    -(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

        NSLog(@"%s", __func__);

    }

     

    @end

  • 相关阅读:
    easyui datagride 两种查询方式
    SharePoint常用目录介绍
    sharepoint 2013 入门1_ 建立一个网页程序
    Windows2012 显示我的电脑
    你知道 react-color 的实现原理吗
    如何实现 Promise 池
    如何使 pdf 文件在浏览器里面直接下载而不是打开
    macOS 安装 oh-my-zsh 之后 node 失效的问题
    剑指offer[47]——求1+2+3+...+n
    剑指offer[46]——孩子们的游戏(圆圈中最后剩下的数)
  • 原文地址:https://www.cnblogs.com/Lu2015-10-03/p/5178373.html
Copyright © 2020-2023  润新知