Embed ImageView in ScrollView with Auto Layout on iOS 6(在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 iOS 6 上使用自动布局在 ScrollView 中嵌入 Image
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01