我有一个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;
}