Ios7 使用Autolayout在导航栏下方强制UIView
在viewDidLoad中,我通过编程创建了一个水平滚动的UIScrollView,将其添加到控制器的视图中,然后设置约束将其推到导航栏下方。但它不起作用,我遗漏了什么(我的自动布局知识很弱,所以我可能遗漏了很多东西)。代码如下:Ios7 使用Autolayout在导航栏下方强制UIView,ios7,uiview,uiscrollview,uinavigationbar,autolayout,Ios7,Uiview,Uiscrollview,Uinavigationbar,Autolayout,在viewDidLoad中,我通过编程创建了一个水平滚动的UIScrollView,将其添加到控制器的视图中,然后设置约束将其推到导航栏下方。但它不起作用,我遗漏了什么(我的自动布局知识很弱,所以我可能遗漏了很多东西)。代码如下: UIScrollView *scrollingView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 40)]; sel
UIScrollView *scrollingView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 40)];
self.scrollingView = scrollingThumbsScrubber;
self.scrollingView.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.scrollingView];
if ([self respondsToSelector:@selector(topLayoutGuide)]) {
[self.scrollingView setTranslatesAutoresizingMaskIntoConstraints: NO];
id topGuide = self.topLayoutGuide;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (scrollingView, topGuide);
[self.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat: @"V:[topGuide]-20-[scrollingView]"
options: 0
metrics: nil
views: viewsDictionary]
];
}
实际发生了什么错误 简单的呼唤
[self.view addSubview:self.scrollingView];
然后删除所有代码,会自动将滚动视图放在导航栏下方如果我简单地添加它,它就会出现在导航栏后面。你知道如何实现它吗?