0

我有一个奇怪的问题,我试图覆盖-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);
    }
}

如果我将该行注释掉,我不会收到错误消息。有谁知道为什么会发生这种情况?我错过了什么吗?我已经在我的应用程序的其他地方进行了几乎这种精确的转换,并且效果很好。我一生都无法弄清楚这里发生了什么。我愿意尝试几乎任何事情。

4

1 回答 1

1

好吧,这并不是一个完整的答案,但我想记录我的修复,因为它确实揭示了更多关于问题的信息,并且可能会帮助某人。

所以事实证明,这个问题在某种程度上与界面构建器有关(我认为)。我让故事板实例化了上述 UIVIew 的这个子类(通过更改视图控制器中根视图的类类型)。我还将情节提要中的子视图链接到视图中IBOutlets。显然这做了一些有趣的事情,可能会覆盖或更改一些默认布局机制。

一旦我将视图完全从界面构建器中拉出并实例化并在代码中手动添加所有内容,它就可以正常工作。

于 2013-10-08T19:25:17.580 回答