//
// HJPhotoViewViewController.m
// MusicLove
//
// Created by niuxinghua on 15/2/10.
// Copyright (c) 2015年 Hjojo. All rights reserved.
//
#import "HJPhotoViewViewController.h"
#import "SDWebImageManager.h"
#import "NetTool.h"
#import "UIImageView+WebCache.h"
@interface HJPhotoViewViewController (){
CGFloat lastDistance;
CGFloat imgStartWidth;
CGFloat imgStartHeight;
}
@end
@implementation HJPhotoViewViewController
// 添加所有的手势
- (void) addGestureRecognizerToView:(UIView *)view
{
// 旋转手势
UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateView:)];
[view addGestureRecognizer:rotationGestureRecognizer];
// 缩放手势
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) rotateView:(UIRotationGestureRecognizer *)rotationGestureRecognizer
{
UIView *view = rotationGestureRecognizer.view;
if (rotationGestureRecognizer.state == UIGestureRecognizerStateBegan || rotationGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformRotate(view.transform, rotationGestureRecognizer.rotation);
[rotationGestureRecognizer setRotation:0];
}
}
// 处理缩放手势
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
UIView *view = pinchGestureRecognizer.view;
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
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)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGFloat mainwith=[UIScreen mainScreen].bounds.size.width;
CGFloat mainHeigh=[UIScreen mainScreen].bounds.size.height;
_imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, mainwith, mainHeigh)];
[_imageView setContentMode:UIViewContentModeCenter];
[self.view addSubview:_imageView];
UITapGestureRecognizer * TapGesturRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
[self addGestureRecognizerToView:_imageView];
[_imageView setUserInteractionEnabled:YES];
[_imageView setMultipleTouchEnabled:YES];
[self.view addGestureRecognizer:TapGesturRecognizer];
//所有的app的图像缓存为HJimages
// SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"HJimages"];
// //disk缓存中如果有的花
// [imageCache queryDiskCacheForKey:_imageUrl done:^(UIImage *image, SDImageCacheType cacheType) {
// _imageView.image=image;
// _image=image;
// return ;
// }];
// //缓存中木有的话
// if (!_image) {
//
//
// NSLog(@"here2");
// //加载图片并缓存到disk
// [_imageView sd_setImageWithURL:[NSURL URLWithString:_imageUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
// //取消下载提示
// [imageCache storeImage:image forKey:_imageUrl toDisk:YES];
// }];
// }
//
// else{
// //设置默认的加载失败图片
//
// NSLog(@"here3");
// }
[_imageView sd_setImageWithURL:[NSURL URLWithString:_imageUrl] placeholderImage:[UIImage imageNamed:@"init1.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}];
}
-(void)load{
[_imageView sd_setImageWithURL:[NSURL URLWithString:_imageUrl] placeholderImage:[UIImage imageNamed:@"init1.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}];
}
-(void)tap{
NSLog(@"tap.....");
[self dismissViewControllerAnimated:YES completion:^{
nil;
}];
}
- (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