• 手势(4)判断放大缩小


    #import "MJcostom.h"

    @implementation MJcostom

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            self.backgroundColor=[UIColor yellowColor];
            NSLog(@"现在开始");
            
            _moveView= [[UIView alloc]initWithFrame:CGRectMake(0, 30, 30, 30)];
            _moveView.backgroundColor=[UIColor greenColor];
            
            
            _enlargeView=[[UIView alloc]initWithFrame:CGRectMake(50, 100, 50, 50)];
            _enlargeView.backgroundColor=[UIColor
                                          blueColor];
            
            [self addSubview:_moveView];
            [self addSubview:_enlargeView];
            
            self.multipleTouchEnabled=YES;
            
        }
        return self;
    }


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

        _moveView= [[UIView alloc]initWithFrame:CGRectMake(50, 30, 30, 30)];
        _moveView.backgroundColor=[UIColor greenColor];
        [self addSubview:_moveView];
        
        if (touches.count==2) {
            
            NSArray *touch = [touches allObjects];
            
            _first= [touch[0] locationInView:self];
            _second=[touch[1] locationInView:self];
            
            _enlargeView.center= CGPointMake(((_first.x+_second.x)/2), ((_first.y+_second.y)/2));
            
            
            _distance= (powf(_first.x-_second.x, 2) )+( powf(_first.y-_second.y, 2));
            NSLog(@"%lf",_distance);
         
        }
    }

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
    }


    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];

            CGPoint currentPoint = [touch locationInView:self];
        
            self.moveView.center=currentPoint;
        
        if (touches.count==2) {
            NSArray *touchend =[touches allObjects];
            
            CGPoint firstend =[touchend[0] locationInView:self];
            CGPoint secondend= [touchend[1] locationInView:self];
            
            float distanceend;
             distanceend= (powf(firstend.x-secondend.x, 2) )+( powf(firstend.y-secondend.y, 2));
            NSLog(@"%lf",distanceend);
            
            if (distanceend>_distance) {
                NSLog(@"放大");
            }else
            {
                NSLog(@"缩小");
          }

        }
      
    }

  • 相关阅读:
    忍者必须死3 模拟器按键设置
    C# 工厂模式 个人基本流程
    WPF Boolean类型转化器收集 反转转化器
    Json实体类驼峰名称转化器
    TDengine + EMQ X + Grafana 轻松搭建高效低成本的边缘侧工业互联网平台
    呼声最高的数据更新功能来了,用户需要什么,我们就开源什么
    年轻人不讲武德,TDengine边缘侧数据存储方案挑战SQLite
    保姆级演示一分钟搞定TDengine的下载安装
    双汇大数据方案选型:从棘手的InfluxDB+Redis到毫秒级查询的TDengine
    HiveMQ TDengine extension 使用指南
  • 原文地址:https://www.cnblogs.com/wangdelong/p/3848546.html
Copyright © 2020-2023  润新知