缩放视图控制器.h
@interface ZoomViewController : UIViewController <UIScrollViewDelegate>
{
ForecastImage* detailImage; // wrapper class around UIImage (optional - could just be UIImage)
IBOutlet UIImageView* imageView;
IBOutlet DoubleTapScrollView* zoomableScrollView;
}
@property (readwrite, nonatomic, retain) ForecastImage* detailImage;
- (IBAction) dismissZoomViewController;
- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView;
- (void) scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;
@end
缩放视图控制器.m
@implementation ZoomViewController
@synthesize detailImage;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
[imageView setImage:[self.detailImage renderedImage]];
[zoomableScrollView setContentSize:[[imageView image] size]];
[zoomableScrollView setMaximumZoomScale:5.0];
[zoomableScrollView setMinimumZoomScale:0.25];
}
- (void) viewDidAppear:(BOOL)animated
{
self.navigationItem.title = [SearchService getDisplayName:[self.detailImage forecastArea]];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc
{
imageView.image = nil;
self.detailImage = nil;
[super dealloc];
}
- (IBAction) dismissZoomViewController
{
[self dismissModalViewControllerAnimated:YES];
}
#pragma mark Pinch-n-Zoom
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return imageView;
}
- (void) scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
CGSize newSize = CGSizeMake(imageView.image.size.width * scale, imageView.image.size.height * scale);
[scrollView setContentSize:newSize];
}
@end