//
// 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