我正在尝试为 Mac OS X 10.7 进行自动布局设计。
我的应用程序有一个固定宽度/高度的窗口。我真正想做的是调整窗口中控件的大小。例如,我有一个搜索字段,如果单击它应该展开和折叠。我在左侧放置了一个 NSPathControl,如果 NSSearchField 展开,它应该会缩小,因此它们不会折叠。
现在,如果我调整窗口大小,它可以工作,但如果我在代码中设置视图的框架,它不会。自动布局只是忽略了这一点。
我只是在做[[this animator] setFrame:newFrame];
。
有什么我必须在自动布局中启用的,还是我必须在代码中以不同的方式设置框架?
编辑
self.translatesAutoresizingMaskIntoConstraints = YES;
通过在搜索字段中进行设置,我得到了约束。我不确定这是否是个好主意。
此外,它给了我以下日志:
2012-12-12 19:41:30.958 Expanding Search[1428:303] Unable to simultaneously satisfy constraints:
(
"<NSAutoresizingMaskLayoutConstraint:0x101a0d800 h=&-- v=&-- H:[ITSearchField:0x10011bb20]-(1)-| (Names: '|':ITPathbar:0x10190a670 )>",
"<NSLayoutConstraint:0x10190c520 H:[ITSearchField:0x10011bb20]-(2)-| (Names: '|':ITPathbar:0x10190a670 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x10190c520 H:[ITSearchField:0x10011bb20]-(2)-| (Names: '|':ITPathbar:0x10190a670 )>
Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens. And/or, break on objc_exception_throw to catch this in the debugger.
2012-12-12 19:41:32.835 Expanding Search[1428:303] 74
2012-12-12 19:41:32.854 Expanding Search[1428:303] Unable to simultaneously satisfy constraints:
(
"<NSAutoresizingMaskLayoutConstraint:0x101a0d800 h=&-- v=&-- H:[ITSearchField:0x10011bb20]-(14.5)-| (Names: '|':ITPathbar:0x10190a670 )>",
"<NSLayoutConstraint:0x10190c520 H:[ITSearchField:0x10011bb20]-(2)-| (Names: '|':ITPathbar:0x10190a670 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x10190c520 H:[ITSearchField:0x10011bb20]-(2)-| (Names: '|':ITPathbar:0x10190a670 )>
Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens. And/or, break on objc_exception_throw to catch this in the debugger.