gpt4 book ai didi

ios - subview 可见,但框架位于 super View 框架之外

转载 作者:行者123 更新时间:2023-11-29 00:31:05 26 4
gpt4 key购买 nike

我有一个父 VC,它在其中加载一个子 VC。父VC中的代码如下:

self.draggerViewController = [[DraggerViewController alloc] initWithSuperView:self.view];

子VC的代码如下:

- (instancetype)initWithSuperView:(UIView*)superView {
self = [super init];

if (self) {
self.superView = superView;

[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
[superView addSubview:self.view];

[superView addConstraint:[NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0]];

[superView addConstraint:[NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]];

self.constraintDraggerAttributeBottom = [NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
[superView addConstraint:self.constraintDraggerAttributeBottom];
}

return self;
}

使用此代码, subview 在其父 View 上可见,并且正确应用了约束,以便将其放置在父 View 的底部,前导和尾随均为 0。但是, View 的真实框架位于父 View 之外父 View 。

也就是说,我可以在父 View 的底部看到 subview ,但是这个 subview 的框架是frame = (0 -315; 768 35)。

如果我将“clipToBounds”设置为“YES”, View 将放置在真实框架上,但现在约束未正确应用。

如何使用约束将此子 VC 放置在父 VC View 中我想要的位置?

谢谢!

最佳答案

好的,知道了...

我忘记了 View 的高度限制......真可惜......

[superView addConstraint:[NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]];

谢谢大家!

关于ios - subview 可见,但框架位于 super View 框架之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41810190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com