我正在尝试创建一个包含scrollView + clipView + actualView的窗口,该窗口在所有方向上延伸到窗口的大小,但是我无法快速,我是新约束,这是我的代码滚动我在窗口调整大小的实际视图...这是不期望的......
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
{
self = [super initWithContentRect:contentRect styleMask:aStyle backing:bufferingType defer:flag];
if (self)
{
//Create subviews
_scrollView = [[DocumentScrollView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[_scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
_clipView = [[NSClipView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[_clipView setTranslatesAutoresizingMaskIntoConstraints:NO];
_documentView = [[DocumentView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
[_documentView setTranslatesAutoresizingMaskIntoConstraints:NO];
//Add views
[_clipView setDocumentView:_documentView];
[_clipView addSubview:_documentView];
[_scrollView addSubview:_clipView];
[self.contentView addSubview:_scrollView];
//Configure constraints
NSDictionary *views = NSDictionaryOfVariableBindings(_documentView, _scrollView, _clipView);
[_clipView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_documentView]|"
options:0
metrics:nil
views:views]];
[_clipView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_documentView]|"
options:0
metrics:nil
views:views]];
[_scrollView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_clipView]|"
options:0
metrics:nil
views:views]];
[_scrollView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_clipView]|"
options:0
metrics:nil
views:views]];
[self.contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_scrollView]|"
options:0
metrics:nil
views:views]];
[self.contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_scrollView]|"
options:0
metrics:nil
views:views]];
//[self visualizeConstraints:[_scrollView constraints]];
}
return self;
}
任何人都知道如何使这个工作?
亲切的问候
克里斯