0
私はクラスを作成します:ZpTabBar; クラスはサブビューを追加する必要があります。このサブビューの名前はZpTabBarItemです。iOS 7でのVFLの使い方
ZpTabBarItemでは、VFLを使いこのクラスを設計します。
--------------------------------------
ZpTabBar add some ZpTabBarItem
--------------------------------------
- (void) setTabBarItems:(NSArray<ZpTabBarItem *> *)tabBarItems
{
[self removeAllBackupSubviews] ;
if(nil == tabBarItems || 0 == [tabBarItems count]){
return ;
}
NSUInteger tag = 0 ;
for(ZpTabBarItem *item in tabBarItems){
[item setTag:tag] ;
[self addSubview:item] ;
[item initVFLAutoLayout] ; // Core code , init VFL
if(self.delegate && [self.delegate respondsToSelector:@selector(zpTabBar:needUseVFLWithIndex:)]){
NSArray<id<ZpTabBarExcVFLModel>>* modelArr = [self.delegate zpTabBar:self needUseVFLWithIndex:tag] ;
if(nil != modelArr && [modelArr count] > 0){
[item removeZpTabBarItemAllConstraints] ;
for(id<ZpTabBarExcVFLModel> model in modelArr){
[item excLayoutWithExcVFLModel:model] ;
}
}
}
tag ++ ;
}
tag = 0 ;
[self.backup_tabBarItems addObjectsFromArray:tabBarItems] ; // 把数据备份了
[self adjustSubviewsFrame];
}
をそして、あなたはZpTabBatItemのinitVFLAutoLayout
--------------------------------------
ZpTabBarItem
--------------------------------------
- (void) initVFLAutoLayout
{
if(NO == self.pri_componentCompleteAutoLayout && self.iconV && self.titleL){
[self setPri_componentCompleteAutoLayout:YES] ;
[self setTabBarItemModel:^ZpTabBarItemModel *{
return self.tabBarItemModel ? self.tabBarItemModel : [[ZpTabBarItemModel alloc] init] ;
}()] ; // 导入一个默认数据
[self excLayoutWithVisulFormatString:@"V:|-topMargin-[iconV(==22)]-padding-[titleL]-bottomMargin-|" iconVFLKey:@"iconV" titleVFLKey:@"titleL" options:NSLayoutFormatAlignAllCenterX metrics:@{@"topMargin":@6,@"bottomMargin":@2,@"padding":@2}] ; // 界面
[self excLayoutWithVisulFormatString:@"H:[iconV(==22)]" iconVFLKey:@"iconV" titleVFLKey:nil options:NSLayoutFormatAlignAllCenterY metrics:nil] ;
[self excLayoutWithVisulFormatString:@"H:|-[titleL]-|" iconVFLKey:nil titleVFLKey:@"titleL" options:NSLayoutFormatAlignAllLeading|NSLayoutFormatAlignAllTrailing metrics:nil] ;
}
}
- (void) layoutSubviews
{
[super layoutSubviews] ;
[self.onClickButton setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)] ;
[self bringSubviewToFront:self.onClickButton] ;
}
アプリをアプリケーションを実行し、起動見ることができます....... エラー:
あなたは、このコアコードを見ることができます! XcodeのIDEは、あなたのアプリのためにエラーを投げた:
-----------------------------
**Error description:**
-----------------------------
2016-08-17 16:00:09.526 YaoCaiBao[834:60b] *** Assertion failure in -[ZpTabBarItem layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2935.137/UIView.m:8794
2016-08-17 16:00:09.528 YaoCaiBao[834:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. ZpTabBarItem's implementation of -layoutSubviews needs to call super.'
*** First throw call stack:
(0x2f329fd3 0x39ba2ccf 0x2f329ead 0x2fcd6d5b 0x31b45e39 0x317c362b 0x317bee3b 0x317beccd 0x317be6df 0x317be4ef 0x31bc4a0b 0x31baf927 0x31b4b709 0x31b4a871 0x31baecc9 0x341b7aed 0x341b76d7 0x2f2f4ab7 0x2f2f4a53 0x2f2f3227 0x2f25df0f 0x2f25dcf3 0x31badef1 0x31ba916d 0x186a61 0x3a0afab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
質問: 1、VFLがエラーを持っているのはなぜ?
2、どのようにこの問題を解決するには?
助けてください、ありがとう...
これはあなた自身の質問に答えますか?もしそうなら、この答えがどのようにあなたの問題を解決するかを詳しく述べて、コードを適切にフォーマットしてください。 – ekad
はい、これは私の答えです。私はなぜそれがiOSのバグだろうと思っているのですか? – user5465320
私はそれがiOSのバグだと思います – user5465320