我正在尝试使用具有自动布局的新 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Xcode 4 的 Interface Builder 中滚动 UIScrollViewScrolling through UIScrollView in Interface Builder for Xcode 4(在 Xcode 4 的 Interface Builder 中滚动 UIScrollView)
滑动删除嵌入在 UIScrollView 中的 UITableViewswipe to delete in a UITableView which is embeded in a UIScrollView(滑动删除嵌入在 UIScrollView 中的 UITableView)
检查 UIScrollView 中的滚动方向Check direction of scroll in UIScrollView(检查 UIScrollView 中的滚动方向)
UIScrollView 不滚动?UIScrollView Not Scrolling?(UIScrollView 不滚动?)
UIScrollView 如何从其子视图中窃取触摸?How does UIScrollView steal touches from its subviews?(UIScrollView 如何从其子视图中窃取触摸?)
使用自动布局将子视图的宽度与其父视图匹配Matching subview#39;s width to it#39;s superview using autolayout(使用自动布局将子视图的宽度与其父视图匹配)