0

我似乎无法使用 UIViewContentModeScaleAspectFit 属性在我的滚动视图中缩放我的 imageView 以适应滚动视图的大小。

- (void)loadView {
UIImage* image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.moilum.com/images/atomicongallery/setmenu/setmenu1.jpg"]]];
imageView = [[UIImageView alloc]initWithImage:image];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:applicationFrame];
[scrollView addSubview:imageView];
scrollView.contentSize = image.size;
scrollView.minimumZoomScale = 0.3;
scrollView.maximumZoomScale = 3.0;
scrollView.clipsToBounds = NO;
scrollView.delegate = self;
self.view = scrollView;

}

我也试过 imageView.contentMode = UIViewContentModeScaleAspectFill 。scrollView.contentmode = UIViewContentModeScaleAspectFill 也是如此。一切似乎都不起作用:(

有什么办法吗!?

干杯!

4

2 回答 2

0

你有没有尝试过,

-(void)loadView
{
      CGRect frame = CGRectMake(0, 0, scrollView.frame.size.width, scrolllView.frame.size.height);
      imageView = [[UIImageView alloc] initWithFrame:frame];
      imageView.image = [UIImage imageNamed:@"yourimage.png"];
      imageView.contentMode = UIViewContentModeScaleAspectFit;
      [scrollView addSubView:imageView];
      scrollView.contentSize = CGSizeMake( imageView.frame.size.width, imageView.frame.size.height);
 }

我从我的 iPad 上编写了这段代码,我认为这应该可以,如果您有任何问题,请告诉我。

祝你好运。

于 2011-07-26T07:45:43.163 回答
0

如果您没有在 UIScrollViewDelegate 上实现该- (UIView *)viewForZoomingInScrollView:(UIScrollView *)sView方法,则 UIScrollView 将不会调整其 zoomScale。

像这样的东西

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)sView 
{
  NSArray *subViews = [sView subviews];
  if([subViews count] > 0){
     return [subViews objectAtIndex:0];
  }
  return nil;
}

(但显然也没有设置委托。)

于 2011-07-29T10:58:35.657 回答