• 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

  • 相关阅读:
    js模版引擎Mustache介绍
    springMVC学习篇
    MyBatis参数传入集合之foreach动态sql
    eclipse注册码生成,在eclipse3.3.x上测试可用
    B
    jAVA笔记二
    J 分班(class)(NYIST 2019年校赛)
    H 幻方变换(puzzle)(NYIST 2019年校赛)
    E 旅游方案(travel)(南阳理工学院2019年校赛)
    ACM Computer Factory(网络流 POJ 3436,这可是我第一次写网络流)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3188442.html
Copyright © 2020-2023  润新知