Ambiguous Layout
这似乎表明NSScrollVIEw和auto Layout不能很好地协同工作.这有点说明iOS和& OSX自动布局指南示例是UIScrollVIEw而不是NSScrollVIEw:
Auto Layout Examples
我把一个例子拼凑在一起.主窗口包含一个拆分视图,右侧有一些固定内容,一个视图将在左侧以编程方式填充. (我会张贴一张照片,但我还没有所需的声誉).运行下面的代码,任何移动分割器的尝试都会导致它回到原始位置.
AppDelegate.h#import <Cocoa/Cocoa.h>@interface AppDelegate : NSObject <NSApplicationDelegate>@property (weak) IBOutlet NSScrollVIEw *scrollVIEw;@property (strong,nonatomic) NSVIEw *containerVIEw;@property (strong,nonatomic) NSMutableDictionary *vIEws;@property (assign) IBOutlet NSWindow *window;@endAppDelegate.m#import "AppDelegate.h"@implementation AppDelegate@synthesize scrollVIEw;@synthesize containerVIEw;@synthesize vIEws;- (voID)applicationDIDFinishLaunching:(NSNotification *)aNotification{ // Insert code here to initialize your application}-(voID)awakeFromNib {// Create a container to hold all the subvIEwscontainerVIEw = [[NSVIEw alloc] initWithFrame:NSZeroRect];[containerVIEw setTranslatesautoresizingMaskIntoConstraints:NO];[scrollVIEw setdocumentVIEw:containerVIEw];vIEws = [[NSMutableDictionary alloc] init];for (int i=0; i<8; i++) { NSBox *Box = [[NSBox alloc] init]; Nsstring *Title = [Nsstring stringWithFormat:@"Box%@",[[NSNumber numberWithInt:i] stringValue]]; Box.Title = Title; [vIEws setobject:Box forKey:Title]; [Box setTranslatesautoresizingMaskIntoConstraints:NO]; [containerVIEw addSubvIEw:Box];}long height = 160;NSArray *sortedKeys = [[vIEws allKeys] sortedArrayUsingSelector: @selector(compare:)];for(Nsstring *vIEwname in sortedKeys) { [containerVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[[Nsstring alloc] initWithFormat:@"|-20-[%@]-20-|",vIEwname] options:0 metrics:nil vIEws:vIEws]]; [containerVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[[Nsstring alloc] initWithFormat:@"V:[%@(==%ld)]",vIEwname,height] options:0 metrics:nil vIEws:vIEws]];}// Build the subvIEw-to-subvIEw constraint stringNsstring *constraintString = @"V:|";for(Nsstring *vIEwname in sortedKeys) { constraintString = [constraintString stringByAppendingString:[Nsstring stringWithFormat:@"-20-[%@]",vIEwname]];}// SubvIEw-to-subvIEw constraints[containerVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:constraintString options:0 metrics:nil vIEws:vIEws]];// Container vIEw constraintsNSDictionary *topLevelDictionary = NSDictionaryOfVariableBindings(containerVIEw);[scrollVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[containerVIEw]-0-|" options:0 metrics:nil vIEws:topLevelDictionary]];[scrollVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[containerVIEw]" options:0 metrics:nil vIEws:topLevelDictionary]];[scrollVIEw addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[[Nsstring alloc] initWithFormat:@"V:|[containerVIEw(==%ld)]",(long)(20 + height) * sortedKeys.count + 20] options:0 metrics:nil vIEws:topLevelDictionary]];}@end
任何方向将不胜感激.
解决方法 我有同样的问题. autolayout和NssplitVIEw一起玩很好,你只需要牺牲正确的鸡肉.尝试在相关的分割部分设置稍高的保持优先级.图像显示我最右边的分割将优先考虑.
另一个考虑因素.相关分割宽度的内容是否受到限制?您可能需要对其宽度设置大于或等于约束,例如| -0- [mysplitcontent(> = minwIDth)] – 0- |
总结以上是内存溢出为你收集整理的objective-c – 嵌入在NSSplitView中的NSScrollView中的NSView的自动布局全部内容,希望文章能够帮你解决objective-c – 嵌入在NSSplitView中的NSScrollView中的NSView的自动布局所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)