Кнопка над NSScrollView с использованием autoLayout

У меня есть проект Cocoa, использующий Autolayout, и я хочу поместить кнопку (на самом деле NSPathControl) над NSScrollView, чтобы она оставалась на том же месте на экране, даже когда прокручивается scrollView.

Всякий раз, когда я добавляю кнопку к родительскому элементу scrollView, она оказывается позади scrollView (даже если я явно использую addSubview:positioned:relativeTo:. Как мне заставить ее плавать над scrollView?

Мой запасной вариант - поместить его внутрь scrollView, включить translatesAutoresizingMaskIntoConstraints и обновить фрейм по мере прокрутки scrollView. Я бы предпочел использовать autolayout, если это возможно...

Изменить: вот код макета для кнопки (макет содержимого в scrollView довольно сложный):

NSButton *button = [[NSButton alloc]initWithFrame:NSZeroRect];
button.translatesAutoresizingMaskIntoConstraints = NO;
button.wantsLayer = YES;//Added incase this affects ordering (it doesn't seem to make a difference)
[self.superview addSubview:button positioned:NSWindowAbove relativeTo:self];

[self.superview addConstraint:[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20]];
[self.superview addConstraint:[NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:20]];

person Jon Hull    schedule 28.07.2013    source источник
comment
Можете ли вы добавить свой код автоматического макета?   -  person Keith Smiley    schedule 28.07.2013
comment
Добавил пример кода. Он находится в подклассе NSScrollView.   -  person Jon Hull    schedule 28.07.2013
comment
Здесь нет ничего в ваших ограничениях по поводу scrollView? У вас есть и другие?   -  person Keith Smiley    schedule 28.07.2013
comment
self - это scrollView в этом случае   -  person Jon Hull    schedule 28.07.2013


Ответы (1)


Решено, установив для wantLayer значение YES в самом scrollView.

person Jon Hull    schedule 28.07.2013