I've got a strange issue where I'm trying to override -layoutSubviews
to create a different layout in landscape. My method works fine in portrait, but when I set a transform on one of my subviews in landscape, I get this error:
*** 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.'
My method is as follows:
-(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);
}
}
If I comment that line out, I don't get the error. Does anybody know why this would happen? Am I missing something? I've done almost this exact transform elsewhere in my app and it works just fine. I cannot for the life of me figure out what is going on here. I'm willing to try pretty much anything.
Well, this isn't really a full answer, but I wanted to document my fix since it does reveal a little more about the problem, and could possibly help someone out.
So it turns out that the issue was somehow related to the interface builder (I think). I had this subclass of UIVIew described above being instantiated by the storyboard (by changing the class type of the root view in the view controller). I was also linking the subviews in the storyboard to
IBOutlets
in the view. Apparently that does some funny stuff, perhaps overriding or changing some of the default layout mechanisms.Once I pulled the view completely out of interface builder and instantiated and added everything manually in code, it worked fine.