我很喜歡使用UIScrollView縮放縮放功能。但問題是滾動視圖中圖像的方面適合度。UIImageView縮放UIScrollView
目前,我有這個,如下圖:
但我想圖像要適合屏幕像下圖:
和景觀相同的行爲。我怎樣才能做到這一點?
下面是代碼:
- (void)viewDidLoad
{
UIImage *image = [UIImage imageWithData:appDelegate.selectedOriginalImage];
imgView.image = image;
CGSize imageSize = image.size;
CGRect rect = CGRectMake(0, 0, imageSize.width, imageSize.height);
imgView.frame = rect;
scrollView.contentSize = CGSizeMake(imgView.frame.size.width, imgView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 1.0;
scrollView.delegate = self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIImage *image = [UIImage imageWithData:appDelegate.selectedOriginalImage];
CGSize imageSize = image.size;
CGRect rect = CGRectMake(0, 0, imageSize.width, imageSize.height);
imgView.frame = rect;
[scrollView setContentOffset:CGPointMake(0, 0)];
return YES;
}
它看起來像你的代碼中的ImageView的大小設置爲圖像的原始大小的imgView。我認爲如果你定義了你想要的圖像視圖的大小,並保持方面適合你應該得到你想要的效果。 – propstm