• #在蓝懿学习iOS的日子#day20


    1、touch触发点点击屏幕
    @property (nonatomic, strong)UIImageView *iv;
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.iv = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
        self.iv .backgroundColor =  [UIColor blackColor];
        [self.view addSubview:self.iv];

    }
    //开始
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        //    把set转成array
        //    NSArray *arr = touches.allObjects;
        //NSLog(@"开始");
        //*********获取单个手指坐标
        UITouch*t=[touches anyObject];
        CGPoint p = [t locationInView:self.view];
        self.iv.center = p;
        //在控制台输出的NO.1
        NSLog(@"开始 %f--%f",p.x,p.y);
        //NO.2把中心点转为字符串
         NSLog(@"开始 %@",NSStringFromCGPoint(p));
       //用户点击的数量
        NSLog(@"=====%ld",t.tapCount);
         //*********获取两个
        NSArray *arr = touches.allObjects;
        if (arr.count==2) {
            UITouch *t1 = arr[0];
            UITouch *t2 = arr[1];
           
            CGPoint p1 = [t1 locationInView:self.view];
            CGPoint p2 = [t2 locationInView:self.view];
           
            NSLog(@"p1=%@ p2=%@",NSStringFromCGPoint(p1),NSStringFromCGPoint(p2));
            }
    }
    //移动
    -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
           // NSLog(@"移动");
        UITouch*t=[touches anyObject];
        CGPoint p = [t locationInView:self.view];
           self.iv.center = p;
         NSLog(@"移动 %@",NSStringFromCGPoint(p));
    }
    //结束
    -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
            //NSLog(@"结束");
        UITouch*t=[touches anyObject];
        CGPoint p = [t locationInView:self.view];
           self.iv.center = p;
         NSLog(@"结束 %@",NSStringFromCGPoint(p));
    }
    //因为意外退出
    -(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
            NSLog(@"因为意外退出");
    }
     2、  当用户使用超过一个的触屏点的坐标要勾选
     
    3、超出视图的Bouns不显示
  • 相关阅读:
    vue 分页 pagination
    查看android 签名文件keystore的有效期限
    cordova + vue 项目实现极光推送功能
    vue window
    input
    vue install 组件
    cordova 的安桌动画
    深度图
    css3 Transition动画执行时有可能会出现闪烁的bug
    windows zip命令
  • 原文地址:https://www.cnblogs.com/odileye/p/4969930.html
Copyright © 2020-2023  润新知