大型 UIImage 未缩小到滚动视图的框架中

发布于 2024-11-24 17:51:06 字数 958 浏览 1 评论 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。一切似乎都不起作用:(

有出路吗!?

干杯!

i can't seem to use UIViewContentModeScaleAspectFit property to scale my imageView within my scrollview to fit the scrollview size.

- (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;

}

i have tried imageView.contentMode = UIViewContentModeScaleAspectFill as well. scrollView.contentmode = UIViewContentModeScaleAspectFill as well. All dont seem to work :(

any way out!?

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-12-01 17:51:06

如果您没有在 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;
}

(但显然根本不设置代表也有效。)

The UIScrollView will not adjust its zoomScale if you don't implement the - (UIView *)viewForZoomingInScrollView:(UIScrollView *)sView method on the UIScrollViewDelegate.

Something like this

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

(But apparently not setting a delegate at all works too.)

故人爱我别走 2024-12-01 17:51:06

你有没有尝试过,

-(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 上编写了这段代码,我认为这应该可行,
如果您有任何问题,请告诉我。

祝你好运。

Have you tried,

-(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);
 }

I write this code from my iPad i think this should work,
Let me know if you have any problem.

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文