2

此代码显示滚动视图,但我想要显示的图像(教程)大于视图。换句话说,tutorial.png 正好是 280X1200,但它不会有 aspectFit。我在这里遗漏了一些小东西:

tipScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 10, 280, 1200)];
tipScroll.showsVerticalScrollIndicator = YES;
tipScroll.scrollEnabled = YES;
tipScroll.userInteractionEnabled = YES;

UIImageView *tutorialImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tutorial"]];

tipScroll.contentMode = UIViewContentModeScaleAspectFit;
tutorialImageView.contentMode = UIViewContentModeScaleAspectFit;

tipScroll.contentSize = tutorialImageView.frame.size;

[self.view addSubview:tipScroll];
[tipScroll addSubview:tutorialImageView];
4

1 回答 1

2

请看下面的编辑代码。它会工作

tipScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 10, 280, 1200)];
tipScroll.showsVerticalScrollIndicator = YES;
tipScroll.scrollEnabled = YES;
tipScroll.userInteractionEnabled = YES;

UIImageView *tutorialImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 280, 1200)];
tutorialImageView.image = [UIImage imageNamed:@"tutorial"];

tipScroll.contentSize = tutorialImageView.frame.size;
[tipScroll addSubview:tutorialImageView];
[self.view addSubview:tipScroll];
于 2013-03-15T01:20:37.707 回答