我有一个奇怪的问题,我试图覆盖-layoutSubviews
以在横向中创建不同的布局。我的方法在纵向上运行良好,但是当我在横向上的一个子视图上设置转换时,出现此错误:
*** Assertion failure in -[LSSlideNotesView layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2380.17/UIView.m:5776
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. LSSlideNotesView's implementation of -layoutSubviews needs to call super.'
我的方法如下:
-(void)layoutSubviews {
[super layoutSubviews];
bool horz = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
if (horz) {
CGRect contentFrame = self.bounds;
contentFrame.size.width -= (notesHeight + 40);
if (contentFrame.size.width < 0) {
contentFrame.size.width = 0;
notesHeight = self.bounds.size.width - 40;
}
slideCarouselView.frame = contentFrame;
remotePointerView.frame = contentFrame;
// ***** This is the offending line *****
notesLabel.transform = CGAffineTransformMakeRotation(-M_PI_2);
// **************************************
notesLabel.bounds = CGRectMake(0, 0, contentFrame.size.height, 40);
notesLabel.center = CGPointMake(CGRectGetMaxX(contentFrame) + 20, contentFrame.size.height / 2);
CGRect notesRect = self.bounds;
notesRect.origin.x = notesRect.size.width - notesHeight;
notesRect.size.width = notesHeight;
notesTextView.frame = notesRect;
labelCopyFail.frame = CGRectMake(contentFrame.size.width / 2 - 65, contentFrame.size.height * 3 / 4 - 20, 130, 30);
} else {
CGRect contentFrame = self.bounds;
contentFrame.size.height -= (notesHeight + 40 + keyboardHeight);
if (contentFrame.size.height < 0) {
contentFrame.size.height = 0;
notesHeight = self.bounds.size.height - keyboardHeight - 40;
}
slideCarouselView.frame = contentFrame;
remotePointerView.frame = contentFrame;
notesLabel.transform = CGAffineTransformIdentity;
notesLabel.frame = CGRectMake(CGRectGetMinX(contentFrame), CGRectGetMaxY(contentFrame), contentFrame.size.width, 40);
CGRect notesRect = self.bounds;
notesRect.origin.y = notesRect.size.height - notesHeight - keyboardHeight;
notesRect.size.height = notesHeight;
notesTextView.frame = notesRect;
labelCopyFail.frame = CGRectMake(contentFrame.size.width / 2 - 65, contentFrame.size.height * 3 / 4 - 20, 130, 30);
}
}
如果我将该行注释掉,我不会收到错误消息。有谁知道为什么会发生这种情况?我错过了什么吗?我已经在我的应用程序的其他地方进行了几乎这种精确的转换,并且效果很好。我一生都无法弄清楚这里发生了什么。我愿意尝试几乎任何事情。