3

iOS 6.0 发行说明中有以下声明:

请注意,您可以通过在视图和滚动视图的子树之外的视图(例如滚动视图的超级视图)之间创建约束,使滚动视图的子视图看起来浮动(不滚动)在其他滚动内容之上。

有人有想法么?

4

1 回答 1

2

我做了一些游戏,我有一个工作示例。

视图不滚动,它被放在顶部,高度是滚动视图高度和任意值之间的差异。

// 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];
于 2013-02-17T23:57:37.387 回答