我有一个UIPageViewController半透明的状态栏和导航栏.topLayoutGuide正如预期的那样,它是64像素.
但是,UIPageViewController报告的子视图控制器为topLayoutGuide0像素,即使它们显示在状态栏和导航栏下.
这是预期的行为吗?如果是这样,在真实情况下定位子视图控制器视图的最佳方法是topLayoutGuide什么?
(缺少使用parentViewController.topLayoutGuide,我认为是黑客攻击)
如何在Interface Builder中设置autolayout以垂直排列视图,如图所示:

Top view固定在屏幕顶部边缘,Bottom view固定在屏幕底部边缘.My view应该在顶视图和底视图之间居中(距离Top view等于距离Bottom view)
我的布局约束在Interface Builder中很好,但是由于框架的某些部分应用了我真正不想要的固定高度和宽度约束,因此在运行时会发生异常.为什么他们在那里,以及如何关闭他们?
它们是记录列表中显示的最后两个约束:
2014-04-26 09:02:58.687 BBCNews[32058:60b] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0xbf478a0 UIView:0xbf4a3c0.height == 0.28125*UIView:0xbf4a3c0.width>", …Run Code Online (Sandbox Code Playgroud) 什么会导致以下警告(以及iOS 7上的后续对齐问题)?
属性不可用:相对于8.0之前的iOS版本上的布局边距的布局属性
UIView方法setNeedsLayout和真正的区别是什么setNeedsDisplay?
像往常一样,文档对此很有雾.
我有一个动态高度的视图,我试图在运行时更改此视图高度优先级.
这是我的代码部分;
if (index == 0) {
surveyViewHeightConstraint.constant = 0;
surveyViewHeightConstraint.priority = 1000;
} else if (index == 1) {
surveyViewHeightConstraint.constant = 163;
surveyViewHeightConstraint.priority = 500;
}
Run Code Online (Sandbox Code Playgroud)
我正在用按钮动作改变索引.当我运行此代码时,我收到此错误:
*** Assertion failure in -[NSLayoutConstraint setPriority:], /SourceCache/Foundation/Foundation-1141.1/Layout.subproj/NSLayoutConstraint.m:174
Run Code Online (Sandbox Code Playgroud)
这里的错误是什么?
Apple 关于在视图和其中一个布局指南之间创建自动布局约束的文档仅显示了使用VFL的示例.
有没有办法在没有 VFL(使用NSLayoutConstraint其他API或类似的)的情况下以编程方式创建这些约束?
(注意:我特别要求在代码中执行此操作,而不是在Interface Builder中.我不希望length将指南集的计算设置为约束的静态常量,我想要一个约束,其中布局指南的长度发生变化会自动导致约束视图调整位置.)
是什么区别NSLayoutAttributeLeft和NSLayoutAttributeLeadingiOS中自动版式?
我的应用程序有一个多窗格教程样式视图,用户可以通过该视图了解该应用程序.这非常实现,如本教程中所述.在为iOS 7和8实现它之后,我正在比较它们的工作方式,并找到后者的问题 - 我在这里运行Xcode 6 GM.
似乎UIPageViewController在转换完成后呈现视图.我重写了委托方法,看看发生了什么:
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers
{
NSLog(@"Frame size before: %@", NSStringFromCGRect([(UIViewController*)pendingViewControllers[0] view].frame));
}
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
NSLog(@"Frame size after: %@", NSStringFromCGRect([(UIViewController*)previousViewControllers[0] view].frame));
}
Run Code Online (Sandbox Code Playgroud)
这是一个示例输出:
Frame size before: {{0, 0}, {600, 600}}
Frame size after: {{0, 0}, {320, 568}}
Run Code Online (Sandbox Code Playgroud)
这样表现如下:向左滑动以拉入下一个视图,并在新视图的底部注意32磅的空白区域.转换完成后,它会进入正确的布局.
这可能是iOS 8中的错误吗?在这一点上,我完全没猜到.
我已经为我的视图控制器使用了自动布局.我已经在约束中设置了V和H位置,但我想知道当它变为5s,6和6 Plus时如何增加我的按钮大小.这是我为登录按钮添加约束的方式:
NSArray *btncon_V=[NSLayoutConstraint constraintsWithVisualFormat:@"V:[btnLogin(40)]" options:0 metrics:nil views:viewsDictionary];
[btnLogin addConstraints:btncon_V];
NSArray *btncon_POS_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-100-[btnLogin]-100-|" options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:btncon_POS_H];
NSArray *btncon_POS_V=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-70-[Title]-130-[lblFirst]-0-[lblSecond]-20-[textusername]-10-[txtpassword]-10-[btnLogin]" options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:btncon_POS_V];
Run Code Online (Sandbox Code Playgroud)
但我的问题是,虽然它管理左侧和右侧间隙,但由于高度固定,它在iPhone 6和6 Plus中得到了拉伸.如何根据屏幕尺寸增加尺寸?我认为这可能是宽高比,但我如何在代码中设置宽高比约束?
autolayout ×10
ios ×9
constraints ×3
attributes ×1
ios7 ×1
ios8 ×1
objective-c ×1
uitableview ×1
xcode6 ×1