iphone - 带大图像的 UIScrollView

标签 iphone uiview uiscrollview uiimageview

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

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

最佳答案

请查看下面编辑后的代码。它会起作用

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

关于iphone - 带大图像的 UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423076/

相关文章:

iphone - Apple 会拒绝使用 sksmtpmessage 框架在后台发送电子邮件的应用程序吗?

iphone - 将 Xcode 更新到 5.1 时,EAGLView.mm 中出现错误 "Cast from pointer to smaller type ' int' 丢失信息 (5B130a)

javascript - AngularJS 在某些状态下隐藏 ui-view

ios - 以编程方式创建与点击按钮关联的标签

ios - 从水平 UIScrollView 中删除额外的底部填充

ios - 如何在 Swift 中设置 UIScrollView 高度

ios - UIScrollView 在 vi​​ewDidLoad 中调用 setContentSize 后不会更新,但从按钮调用时会更新

ios - 将大对象从 ViewController 发送到 Objective C 中的另一个,ios?

ios - 如何在 UIView 中绘制 opengl es

iphone+在推送任何 View 时隐藏标签栏