Iphone 如何以编程方式使用Autolayout在视图之间提供垂直空间?
在我的应用程序中,我必须根据每个视图垂直布局两个视图,并确保它们在iPhone4和iPhone5中看起来相似。 代码如下:Iphone 如何以编程方式使用Autolayout在视图之间提供垂直空间?,iphone,autolayout,nslayoutconstraint,Iphone,Autolayout,Nslayoutconstraint,在我的应用程序中,我必须根据每个视图垂直布局两个视图,并确保它们在iPhone4和iPhone5中看起来相似。 代码如下: nextShowView = [[WestwoodNextShowView alloc]initWithFrame:CGRectMake(-5, 322, 290, 70)]; nextShowView.staticLabel.text = @"Next Show"; nextShowView.date.text = @"10/25"; nextSh
nextShowView = [[WestwoodNextShowView alloc]initWithFrame:CGRectMake(-5, 322, 290, 70)];
nextShowView.staticLabel.text = @"Next Show";
nextShowView.date.text = @"10/25";
nextShowView.address.text = @"Green Dot Tavern";
nextShowView.cityState.text = @"Detroit, MI";
[_aboutScroll addSubview:nextShowView];
playerView = [[WestwoodMusicPlayerView alloc]initWithFrame:CGRectMake(0, 407, 320, 50)];
[_aboutScroll addSubview:playerView];
NSDictionary * viewsDict = NSDictionaryOfVariableBindings(nextShowView, playerView);
NSArray * constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[nextShowView]-15-[playerView]-20-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:viewsDict];
[_aboutScroll addConstraints:constraints];
我试图做的是在nextShowView和playerView之间留出15点空间,从playerView底部到视图底部边缘留出20点空间
请帮忙
谢谢,只有当您提供了每个视图完全指定它所需的所有约束时,自动布局才起作用。您不仅必须给出
nextShowView
和playerView
之间的垂直间隔,还必须给出playerView
和superview之间的垂直间隔,以及它们的高度、水平位置和宽度
如果您的视图没有显示在您期望的位置,那么您可能没有提供足够的约束。暂停调试器并在控制台命令行上说po[[UIWindow keyWindow]\u autolayoutTrace]
,以确认布局是否不明确