コードをSwift 3に移行した後に問題が発生しました。 iOS10で新しい問題が発生していると思いますが、実際はSwift自体には関係ありません。レイヤー操作によるSwift UIViewReportBrokenSuperviewChainの理由
エラー:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'View has lost track of its superview, most likely through unsupported use of CALayer API on the view's layer. If this isn't a crash yet, it will be in the near future.
Problem view: <UIToolbar: 0x102552d80; frame = (0 0; 375 683); alpha = 0.97; opaque = NO; layer = <CALayer: 0x1700383e0>>
Expected parent: <MyModelView: 0x10250ecd0; frame = (0 -16; 375 683); hidden = YES; layer = <CALayer: 0x17003d4a0>>
Break on UIViewReportBrokenSuperviewChain to debug.'
問題をトリガーするコードは次のとおりです。
[c presentViewController:tabBarViewController animated:NO completion:^{
問題を担当するサブコードがあると思われる:
- (void)addBlurView
{
CGRect viewBounds = [[UIScreen mainScreen]applicationFrame];
self.myModelView = [[MyModalView alloc] initWithFrame:CGRectMake(viewBounds.origin.x, -16, viewBounds.size.width, viewBounds.size.height+36)];
if(![self toolbar]) {
_toolbar = [[UIToolbar alloc] initWithFrame:[self.myModelView bounds]];
[_toolbar setBarStyle:UIBarStyleBlack];
_toolbar.alpha = 0.97;
[self.myModelView.layer insertSublayer:_toolbar.layer atIndex:0];
}
[self.view addSubview:self.myModelView];
}
なぜレイヤー階層を操作していますか?多分、myModelViewのサブビューとしてツールバーを追加し、この問題を確実に取り除く方が良いでしょうか? – slashdot
これはレガシーコードなので、ここで問題を解決しようとしています。今のところ私はinsertSublayerの問題を削除しました。私はそれが透明性の背景を得るための何らかのトリックであることを発見しました。明らかにそれは既知のトリックだが、それは新しいものでアプリクラッシュを引き起こす。私はそれを終えるとすぐにこの投稿を更新します。 – Mikael
こんにちは@Mikael "デバッグするためにUIViewReportBrokenSuperviewChainを中断してください。"これは何を意味するのですか?私もこのエラーがあり、それは十分に文書化されていません。 –