ScrollView方法
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Cool.jpg"]];
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
self.scrollView.frame=self.view.frame;
self.imageView.frame=self.scrollView.frame;
NSLog(@"%@",NSStringFromCGRect(self.imageView.frame));
[self.imageView setContentMode:UIViewContentModeScaleAspectFit];
self.scrollView.delegate=self;
[self.scrollView setMaximumZoomScale:5.0];
[self.scrollView setMinimumZoomScale:1.0];
[self.scrollView addSubview:self.imageView];
// self.scrollView.contentSize=CGSizeMake(320, 1000);
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark - UIScrollViewDelegate
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.imageView;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}[/code]
Gesture方法
//
// PLGestureZoomDemoVC.m
// ZoomScrollView
//
// Created by liu poolo on 14-4-2.
// Copyright (c) 2014年 liu poolo. All rights reserved.
//
#import “PLGestureZoomDemoVC.h”;
@interface PLGestureZoomDemoVC (){
UIPinchGestureRecognizer *_gst;
float _lastScale;
CGSize beginImageViewSize;
}
@end
@implementation PLGestureZoomDemoVC
- (void)viewDidLoad
{
[super viewDidLoad];
self.image=[UIImage imageNamed:@"Cool.jpg"];
self.imageView=[[UIImageView alloc]initWithImage:self.image];
self.imageView.center=self.view.center;
[self.view addSubview:self.imageView];
_gst=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureResponse:)];
[self.imageView addGestureRecognizer:_gst];
UITapGestureRecognizer *tapGtr=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureResponse:)];
tapGtr.numberOfTapsRequired=2;
[self.imageView addGestureRecognizer:tapGtr];
self.imageView.userInteractionEnabled=YES;
beginImageViewSize=self.imageView.frame.size;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void)pinchGestureResponse:(UIPinchGestureRecognizer *) pinGst{
if(pinGst.state==UIGestureRecognizerStateBegan){
_lastScale=pinGst.scale;
}
float scale=pinGst.scale/_lastScale;
_lastScale=pinGst.scale;
[pinGst.view setTransform:CGAffineTransformScale(pinGst.view.transform, scale, scale)];
NSLog(@"%f",scale);
}
-(void)tapGestureResponse:(UITapGestureRecognizer *) tapGst{
[tapGst.view setTransform:CGAffineTransformScale(tapGst.view.transform, beginImageViewSize.width/tapGst.view
.frame.size.width, beginImageViewSize.height/tapGst.view
.frame.size.height)];
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Cool.jpg"]];
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
self.scrollView.frame=self.view.frame;
self.imageView.frame=self.scrollView.frame;
NSLog(@"%@",NSStringFromCGRect(self.imageView.frame));
[self.imageView setContentMode:UIViewContentModeScaleAspectFit];
self.scrollView.delegate=self;
[self.scrollView setMaximumZoomScale:5.0];
[self.scrollView setMinimumZoomScale:1.0];
[self.scrollView addSubview:self.imageView];
// self.scrollView.contentSize=CGSizeMake(320, 1000);
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark - UIScrollViewDelegate
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.imageView;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}[/code]
Gesture方法
//
// PLGestureZoomDemoVC.m
// ZoomScrollView
//
// Created by liu poolo on 14-4-2.
// Copyright (c) 2014年 liu poolo. All rights reserved.
//
#import “PLGestureZoomDemoVC.h”;
@interface PLGestureZoomDemoVC (){
UIPinchGestureRecognizer *_gst;
float _lastScale;
CGSize beginImageViewSize;
}
@end
@implementation PLGestureZoomDemoVC
- (void)viewDidLoad
{
[super viewDidLoad];
self.image=[UIImage imageNamed:@"Cool.jpg"];
self.imageView=[[UIImageView alloc]initWithImage:self.image];
self.imageView.center=self.view.center;
[self.view addSubview:self.imageView];
_gst=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureResponse:)];
[self.imageView addGestureRecognizer:_gst];
UITapGestureRecognizer *tapGtr=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureResponse:)];
tapGtr.numberOfTapsRequired=2;
[self.imageView addGestureRecognizer:tapGtr];
self.imageView.userInteractionEnabled=YES;
beginImageViewSize=self.imageView.frame.size;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void)pinchGestureResponse:(UIPinchGestureRecognizer *) pinGst{
if(pinGst.state==UIGestureRecognizerStateBegan){
_lastScale=pinGst.scale;
}
float scale=pinGst.scale/_lastScale;
_lastScale=pinGst.scale;
[pinGst.view setTransform:CGAffineTransformScale(pinGst.view.transform, scale, scale)];
NSLog(@"%f",scale);
}
-(void)tapGestureResponse:(UITapGestureRecognizer *) tapGst{
[tapGst.view setTransform:CGAffineTransformScale(tapGst.view.transform, beginImageViewSize.width/tapGst.view
.frame.size.width, beginImageViewSize.height/tapGst.view
.frame.size.height)];
}
@end