1

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

1 回答 1

0

在您的控制器中,您将必须实现:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration

将缩放比例设置为 viewWillAppear 的动画。

于 2012-07-10T19:22:34.967 回答