ios手势识别-缩放和旋转

//
//  ViewController.m
//  zwj-手势识别-缩放和旋转
//
//  Created by zwj on 14-9-16.
//  Copyright (c) 2014年 zwj. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self testPinchGes];
    [self testRotationGes];
}

/**
 *测试捏合手势
 */
-(void)testPinchGes{
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc ] initWithTarget:self action:@selector(pincheView:)];
    [self.imgView addGestureRecognizer:pinch];
    pinch.delegate = self;
}
- (void)pincheView:(UIPinchGestureRecognizer *)pinch
{
//    NSLog(@"%f",pinch.scale);
    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
    pinch.scale = 1;
}

/**
 * 测试旋转手势
 */
-(void) testRotationGes{
    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc ]initWithTarget:self action:@selector(rotationView:)];
    [self.imgView addGestureRecognizer:rotation];
    rotation.delegate = self;
}

-(void)rotationView:(UIRotationGestureRecognizer *) rotation{
//    CGFloat rotationF = rotation.rotation;
//    NSLog(@"旋转%f",rotationF);
    
    rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
    rotation.rotation = 0;
    
//    NSLog(@"1111---%@",self.view);
//    NSLog(@"2222---%@",rotation.view);
}

/**
 *  实现代理方法
 */
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}
@end

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。