//
//  CheckPicViewController.m
//  PTools
//
//  Created by 侯振兴 on 15/8/11.
//  Copyright (c) 2015年 moobox. All rights reserved.
//

#import "CheckPicViewController.h"

@interface CheckPicViewController () {
}

@property (nonatomic, strong) UIImageView *takeImageView;

@end

@implementation CheckPicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    self.takeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _takeImageView.image = _checkImage;
    [self.view addSubview:_takeImageView];
    
//    [self addGestureRecognizerToView:_takeImageView];
//    [_takeImageView setUserInteractionEnabled:YES];
//    [_takeImageView setMultipleTouchEnabled:YES];
    
    // Do any additional setup after loading the view.
}



- (void) addGestureRecognizerToView:(UIView *)view {
    // 缩放手势
    UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)];
    [view addGestureRecognizer:pinchGestureRecognizer];
    
    // 移动手势
    UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)];
    [view addGestureRecognizer:panGestureRecognizer];
}

// 处理缩放手势
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer {
    UIView *view = pinchGestureRecognizer.view;
    if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
        view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
        if (_takeImageView.frame.size.width < kScreenWidth) {
            _takeImageView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
            //让图片无法缩得比原图小
        }
        if (_takeImageView.frame.size.width > 3 * kScreenWidth) {
            _takeImageView.frame = CGRectMake(-kScreenWidth, -kScreenHeight, 3 * kScreenWidth, 3 * kScreenHeight);
        }
        pinchGestureRecognizer.scale = 1;
    }
}

// 处理拖拉手势
- (void) panView:(UIPanGestureRecognizer *)panGestureRecognizer
{
    UIView *view = panGestureRecognizer.view;
    if (panGestureRecognizer.state == UIGestureRecognizerStateBegan || panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
        CGPoint translation = [panGestureRecognizer translationInView:view.superview];
        [view setCenter:(CGPoint){view.center.x + translation.x, view.center.y + translation.y}];
        [panGestureRecognizer setTranslation:CGPointZero inView:view.superview];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
