zoukankan      html  css  js  c++  java
  • ios 中手势用法

    pan拖动手势

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self Pan];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    #pragma mark -拖动手势Pan
    -(void)Pan{
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(100, 50, 100, 100)];
        view.backgroundColor=[UIColor redColor];
        [self.view addSubview:view];
        [view release];
        
        UIPanGestureRecognizer *pin=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pin:)];
        [view addGestureRecognizer:pin];
        [pin release];
    }
    
    -(void)pin:(UIPanGestureRecognizer*)pin{
        //得到pin移动的位置,向左拖动是左拖动x为负数,向上拖动y为负数,向下拖动y为整数,向右边拖动为x为整数
        CGPoint point= [pin translationInView:self.view];
        NSLog(@"%@",NSStringFromCGPoint(point));
        //手势结束的状态
        if(pin.state==UIGestureRecognizerStateEnded){
            NSLog(@"手指已离开屏幕,手势结束");
        }
        
        //注意一定要加下面一句 ,清除手势为原来坐标
        [pin setTranslation:CGPointZero inView:self.view];
        
    }

     缩放手势

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self Princh];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    #pragma mark -Princh
    -(void)Princh{
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
        view.backgroundColor=[UIColor redColor];
        [self.view addSubview:view];
        UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
        [view addGestureRecognizer:pinch];
        [pinch release];
        
        [view release];
        
    }
    
    -(void)pinch:(UIPinchGestureRecognizer *)pin{
        
        //主要属性
        CGFloat scale= pin.scale;
        pin.view.transform=CGAffineTransformScale(pin.view.transform, pin.scale, pin.scale);
        if(pin.state==UIGestureRecognizerStateEnded){
            
        }
        scale=1;
        
    }

    缩放

        [self Rotaion];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    #pragma mark -Princh
    -(void)Rotaion{
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
        view.backgroundColor=[UIColor redColor];
        [self.view addSubview:view];
        UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rote:)];
        [view addGestureRecognizer:rotation];
        
        [view release];
        
    }
    
    -(void)rote:(UIRotationGestureRecognizer *)rotation{
        CGFloat rt=rotation.rotation;
        rotation.view.transform=CGAffineTransformRotate(rotation.view.transform, rt);
        if(rotation.state==UIGestureRecognizerStateEnded){
            
        }
        rt=0;
    }

     Tap手势

    -(void)Rotaion{
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
        view.backgroundColor=[UIColor redColor];
        [self.view addSubview:view];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        [view addGestureRecognizer:tap];
        [tap release];
        
    }
    
    
    -(void)tap:(UITapGestureRecognizer *)tap{
        tap.view.backgroundColor=[UIColor yellowColor];
    }

     原文地址:http://blog.csdn.net/totogo2010/article/details/8615940

  • 相关阅读:
    CentOS7设置开机自启动命令大全
    CentOS查看何人何时登陆用户
    CentOS显示设置时间命令- date
    CentOS系统命令
    CentOS系统中last命令的作用
    CentOS命令top下你不一定懂的cpu显示信息
    CentOS系统安装后的基础优化
    查看CentOS的网络带宽出口
    storm深入研究
    hadoop学习笔记之-hbase完全分布模式安装-5
  • 原文地址:https://www.cnblogs.com/gcb999/p/3188442.html
Copyright © 2011-2022 走看看