Mam niestandardowy widok, który wyświetla UILabel w prawym dolnym rogu. Widok jest ustawiona w sposób nazywany zarówno initWithCoder:
i initWithFrame:
tak:Awaria programu Autolayout podczas stosowania przekształcenia: niepowodzenie asercji w - [layoutSublayersOfLayer:]
MCLabel* likesLabel = [[MCLabel alloc] init];
likesLabel.mc_textPadding = UIEdgeInsetsMake(0, 10, 0, 10);
likesLabel.font = [UIFont fontWithName:@"FontAwesome" size:12.f];
[likesLabel setText:@"test"];
likesLabel.numberOfLines = 2;
likesLabel.backgroundColor = [UIColor colorWithWhite:1 alpha:.8];
likesLabel.textColor = UIColor.blackColor;
likesLabel.translatesAutoresizingMaskIntoConstraints = NO;
likesLabel.textAlignment = NSTextAlignmentCenter;
likesLabel.mc_verticalTextAlignment = MCVerticalTextAlignmentTop;
[self addSubview:likesLabel];
self.likesLabel = likesLabel;
NSLayoutConstraint* widthConstraint = [NSLayoutConstraint constraintWithItem:likesLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeWidth multiplier:1 constant:1];
NSLayoutConstraint* heightConstraint = [NSLayoutConstraint constraintWithItem:likesLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:likesLabel attribute:NSLayoutAttributeWidth multiplier:2/5.f constant:1];
NSLayoutConstraint* horizontalPosition = [NSLayoutConstraint constraintWithItem:likesLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:1];
NSLayoutConstraint* verticalPosition = [NSLayoutConstraint constraintWithItem:likesLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1 constant:1];
[likesLabel addConstraints:@[heightConstraint]];
[self addConstraints:@[widthConstraint, horizontalPosition, verticalPosition]];
Teraz, jeśli mogę zostawić wszystko tak nie mam jakiegokolwiek problemu, ale jak tylko zastosować transformację do tej etykiety (to jest podklasą UILabel, które po prostu dodać Vertical Alignment krawędź wypustki i jeśli to ma znaczenie) Aplikacja ulega awarii z powodu błędu w konsoli:
*** Assertion failure in -[MCView layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2935.138/UIView.m:8794
Auto Layout still required after executing -layoutSubviews
wskazań twierdzenie, że prawdopodobnie podklasa nie zadzwonił [super layoutSubviews]
gdy nadrzędne metody, ale zrobiłem.
Ponieważ jest jasne, że problemem jest tutaj konfiguracja autolayout Obawiam się, że coś przeoczyłem i być może układ jest niejednoznaczny, a więc awaria.
Jeszcze jedna uwaga: ten sam kod nie ulega awarii na iOS 8, jeśli przeniesię transformację w metodzie - (void)didMoveToSuperview
.
Ktoś, kto może tutaj pomóc?