我创建了一个自定义的IB可设计视图(请参阅下面的代码),它在IB中正确呈现,并且在运行时也能正常工作.但是,在获取有关视图错位的警告时,我无法在Interface Builder中手动调整视图大小(当触摸调整大小手柄时,视图将在其容器中跳转).
我对各种不同的布局都有相同或类似的行为.如果我在这里做错了,或者这只是IB中的一个错误,你有没有想法?
(PS:我不能忽视警告)

编辑:添加约束的截图:

这是代码(标题):
IB_DESIGNABLE
@interface AKATestView : UIView
@end
Run Code Online (Sandbox Code Playgroud)
执行:
@interface AKATestView()
@property(nonatomic)BOOL subviewsCreated;
@property(nonatomic)BOOL subviewConstraintsCreated;
@property(nonatomic)NSDictionary* views;
@end
@implementation AKATestView
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self setupAfterInit];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setupAfterInit];
}
return self;
}
- (void)setupAfterInit
{
[self createSubviews];
}
- (void)createSubviews
{
if (!self.subviewsCreated)
{
self.translatesAutoresizingMaskIntoConstraints = NO;
UILabel* labelView = [[UILabel alloc] initWithFrame:CGRectZero];
labelView.text = …Run Code Online (Sandbox Code Playgroud)