在 iOS 6 上使用自动布局在 ScrollView 中嵌入 Image

Embed ImageView in ScrollView with Auto Layout on iOS 6(在 iOS 6 上使用自动布局在 ScrollView 中嵌入 ImageView)
本文介绍了在 iOS 6 上使用自动布局在 ScrollView 中嵌入 ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用具有自动布局的新 iOS 6 SDK 制作非常简单的元素.我有一个 ImageView 并将其嵌入到 ScrollView 中.(一切都使用 Interface Builder 构建)..png 文件已设置,imageView 模式设置为左上角".

I am trying to make very simple element with new iOS 6 SDK with auto layout. I have an ImageView and Embed it in ScrollView. (everything build with Interface Builder). The .png file is set and imageView mode is set to "Top Left".

实施:

#import "ImaginariumViewController.h"

@interface ImaginariumViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end

@implementation ImaginariumViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.scrollView.contentSize = self.imageView.image.size;
    self.imageView.frame =
    CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);
}

@end

当我运行应用程序时,图像没有滚动.在关闭自动布局(使用支柱和弹簧)的情况下做同样的事情,我正在滚动.我想问题出在约束上.有人可以帮帮我吗?

When I run the app, the image is not scrolled. Doing all the same with auto layout turned off (with struts and springs), I have working scrolling. I guess the problem is with constraints. Could anybody help me, please?

推荐答案

我刚刚在更新的教程中遇到了同样的问题.我尝试以编程方式删除约束、诅咒并用头撞墙 - 不走运.

I just encountered the same issue in a tutorial that I was updating. I attempted programmatically deleting constraints, cursing, and banging my head against the wall - no luck.

然而,大约 5 分钟前,我尝试了一些解决了我遇到的另一个问题的方法,并且,ta da!UIScrollView 又开始工作了!解决方案是将设置 UIScrollView contentSize 属性的旧代码移动到 viewDidAppear 的实现中,而不是 viewDidLoad:

About 5 minutes ago, however, I tried something that had fixed another issue I encountered, and, ta da! UIScrollView is working again! The solution was to move the old code that sets the UIScrollView contentSize property into an implementation of viewDidAppear, rather than viewDidLoad:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.theScroller.contentSize=CGSizeMake(200.0,2000.0);
}

我希望这可以帮助其他人遇到自动布局出现的一些问题.

I hope this helps someone else encountering some of the headaches that have appeared with Auto Layout.

这篇关于在 iOS 6 上使用自动布局在 ScrollView 中嵌入 ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
How to send an image with custom keyboard iOS(如何使用自定义键盘IO发送映像)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
How to fix ‘TIC SSL Trust Error’ in iOS?(如何修复 iOS 中的“TIC SSL 信任错误?)
How to use NSURLConnection to connect with SSL for an untrusted cert?(如何使用 NSURLConnection 与 SSL 连接以获得不受信任的证书?)