にUIImageView
埋め込まれていUIScrollView
ます...image
が読み込まれるzoom scale
と、の最大量image
が表示されるように設定されますが、デバイスを回転させるとアスペクトが維持されず、引き伸ばされたように見えます。ビューのモードはに設定されていredraw
ます。
- (void)viewDidLoad
{
[super viewDidLoad];
self.scrollView.delegate = self;
// get the url of the photo from flickr
NSURL* url = [FlickrFetcher urlForPhoto:self.photo format:FlickrPhotoFormatLarge];
// set the scrollview's title to be the title of the picture
self.title = [self.photo objectForKey:FLICKR_PHOTO_TITLE];
// convert the url into an image
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
// set the image as the image in the imageView
[self.imageView setImage:image];
// we will be scrolling over the size of the image
self.scrollView.contentSize = self.imageView.image.size;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIInterfaceOrientation currOrient = self.interfaceOrientation;
self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);
if (currOrient == UIInterfaceOrientationPortrait || currOrient == UIInterfaceOrientationPortraitUpsideDown)
[self.scrollView setZoomScale: self.scrollView.frame.size.height / self.imageView.frame.size.height];
else {
[self.scrollView setZoomScale: self.scrollView.frame.size.width / self.imageView.frame.size.width];
}
// [self.imageView setNeedsDisplay];
// [self.scrollView setNeedsDisplay];
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
scrollView.transform = CGAffineTransformIdentity;
}