iOS 手势(下)

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView* view = [[UIView alloc]initWithFrame:self.view.frame];
    view.frame = CGRectMake(0, 0, 100, 100);
    view.center = self.view.center;
    view.backgroundColor = [UIColor redColor];
    //1 轻拍 单击,双击,多指点击
    //2 长摁
    //3 轻扫
    //4 旋转
    //5 捏合
    //6 拖拽
//    UITapGestureRecognizer

//    //1轻拍
//    UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeViewBackground:)];
//    tapGesture.numberOfTapsRequired = 2;//点击两次
//    tapGesture.numberOfTouchesRequired = 2;//两个手指 模拟器摁住alt模拟
//    [view addGestureRecognizer:tapGesture];
//    
//    //2长摁
//    
//    UILongPressGestureRecognizer* longpress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(changeViewBackground:)];
//    longpress.minimumPressDuration = 2;
//    //当手势结束时也会调用 
//    [view addGestureRecognizer:longpress];
//    //3 清扫
//    UISwipeGestureRecognizer* swipeProcess = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(changeViewBackground:)];
//    [view addGestureRecognizer:swipeProcess];
//    swipeProcess.direction = UISwipeGestureRecognizerDirectionDown;
//    /*
//     UISwipeGestureRecognizerDirectionDown
//     UISwipeGestureRecognizerDirectionUp
//     UISwipeGestureRecognizerDirectionRight
//     UISwipeGestureRecognizerDirectionLeft
//     以最后的方向
//    */
    //6 拖拽
    UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];

    [view addGestureRecognizer:panGesture];//添加到手势


    //5 捏合
    UIPinchGestureRecognizer * pinGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinAction:)];
    [view addGestureRecognizer:pinGesture];

     //4 旋转
    UIRotationGestureRecognizer* rotationGesture = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
    [view addGestureRecognizer:rotationGesture];





    [self.view addSubview:view];


}

-(void)rotationAction:(UIRotationGestureRecognizer*)rotation{
    rotation.view.transform = CGAffineTransformMakeRotation(rotation.rotation);
}

-(void)pinAction:(UIPinchGestureRecognizer*)pin{
    pin.view.transform = CGAffineTransformMakeScale(pin.scale, pin.scale);
    NSLog(@"%f",pin.scale);
}

-(void)panAction:(UIPanGestureRecognizer*)pan{

    CGPoint offsetPoint = [pan translationInView:pan.view];
    NSLog(@"%@",NSStringFromCGPoint(offsetPoint));
    //让view随着手指拖拽而动
    pan.view.transform = CGAffineTransformMakeTranslation(offsetPoint.x, offsetPoint.y);
        NSLog(@"%@",@"pan");
}

-(void)changeViewBackground:(UITapGestureRecognizer*)tap{


        tap.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 /255.0f green:arc4random() % 256 /255.0f blue:arc4random() % 256 /255.0f alpha:1.0];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值