Ich habe eine Ansicht, die programmgesteuert eine Unteransicht erstellt und einige Einschränkungen hinzugefügt. Aus irgendeinem Grund werden die Einschränkungen vollständig ignoriert. Es wird kein Fehler ausgegeben. Die Einschränkungen werden einfach nicht wirksam. Die Unteransicht hat denselben Rahmen wie ihre Superansicht. Ich erwarte es 400x400 und zentriert in seiner Superview. Was mache ich hier falsch? Hier ist meine Initwithframe in der Superview:Warum ignoriert meine programmgesteuerte Ansicht ihre Einschränkungen?
- (id) initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
instructionsView = [[UIView alloc] initWithFrame:frame];
[self addSubview:instructionsView];
[self bringSubviewToFront:instructionsView];
[self addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1.
constant:0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.
constant:0]];
[instructionsView addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.
constant:400]];
[instructionsView addConstraint:[NSLayoutConstraint constraintWithItem:instructionsView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.
constant:400]];
}
return self;
}
ich versucht habe, zu ändern
instructionsView = [[UIView alloc] initWithFrame:frame];
zu
instructionsView = [[UIView alloc] initWithFrame:CGRectZero];
ohne Erfolg.