我有一个问题,我在 UIScrollView 中有一个 UIImageView。在Interface Builder中,UIScrollView占据了整个屏幕,UIImageView占据了整个UIScrollView。问题是,当我有一个面向横向的图像时,我将它设置为适合纵横比,所以我在顶部和底部都有灰色条(这是我想要的)。但是,当我放大照片时,一旦照片放大到足以垂直垂直屏幕,我希望它不会平移到其上方的灰色区域。请参阅我附上的屏幕截图。我基本上希望它在这方面像照片应用程序一样工作。这是我设置 UIScrollView 和 UIImageView 的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.imageView.image = [UIImage imageNamed:@"IMG_0300.JPG"];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.scrollView.clipsToBounds = YES;
self.scrollView.contentSize = self.imageView.bounds.size;
self.scrollView.zoomScale = 1.0;
self.scrollView.maximumZoomScale = 5.0;
self.scrollView.minimumZoomScale = 1.0;
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
提前致谢。
雅各布