我似乎无法弄清楚如何使NSScrollView内的内容正确扩展.我看到了一些描述一般方法的参考文献,但没有具体的内容.
这似乎表明NSScrollView和Auto Layout不能很好地协同工作.有点说明iOS和OSX自动布局指南示例都是UIScrollView而不是NSScrollView:
我把一个例子拼凑在一起.主窗口包含一个拆分视图,右侧有一些固定内容,一个视图将在左侧以编程方式填充.(我会张贴一张照片,但我还没有所需的声誉).运行下面的代码,任何移动分割器的尝试都会导致它回到原始位置.
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;
@end
AppDelegate.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 subviews
containerView = [[NSView alloc] initWithFrame:NSZeroRect];
[containerView setTranslatesAutoresizingMaskIntoConstraints:NO];
[scrollView setDocumentView:containerView];
views …Run Code Online (Sandbox Code Playgroud)