本文介绍了如何使用autolayout使视图浮动在滚动视图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在有以下声明:
任何人都有任何想法吗?
Anyone have any ideas?
推荐答案
我做了一些游戏,我有一个各种工作的例子。
I did some playing around and I have a working example of sorts.
视图不会滚动,它会放在顶部,其高度是scrollview hight和任意值之间的差值。
The view does not scroll, it gets put at the top, with a height that is the difference between the scrollview hight and an arbitrary value.
// in viewDidLoad
UIIView *myView = [[UIView alloc] init];
[self.scrollView addSubview:myView];
myView.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.mapView
attribute:NSLayoutAttributeTop
relatedBy:(NSLayoutRelationEqual)
toItem:self.containerView
attribute:(NSLayoutAttributeTop)
multiplier:1.0
constant:0];
[self.view addConstraint:constraint];
// Give my view some intrinsic size
NSDictionary *dict = NSDictionaryOfVariableBindings(myView);
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[myView]|"
options:(NSLayoutFormatAlignAllBaseline)
metrics:nil
views:dict];
[self.view addConstraints:constraints];
// In view did appear
// calc height from height of scroll view - this is needs work
float height = -self.scrollView.frame.size.height + 250;
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.mapView attribute:NSLayoutAttributeHeight
relatedBy:(NSLayoutRelationEqual)
toItem:self.containerView
attribute:(NSLayoutAttributeHeight)
multiplier:1.0
constant:offset];
[self.view addConstraint:constraint];
这篇关于如何使用autolayout使视图浮动在滚动视图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!