reason: 'Cannot modify constraints for UITabBar managed by a controller'
来源:互联网 发布:类似iebook的软件 编辑:程序博客网 时间:2024/06/05 02:51
当在UITabBarController底部TabBar自定义的时候,我自定义了一个View,然后添加到系统自带的tabBar上。因为当APP打开时,我要任意切换横屏和竖屏,所以我要让自定义的tabBar适配屏幕。
- (void)setupTabbar{
WWTabBar *customTabBar = [[WWTabBaralloc]init];
customTabBar.backgroundColor = [UIColorwhiteColor];
customTabBar.delegate =self;
[self.tabBaraddSubview:customTabBar];
self.customTabBar = customTabBar;
[customTabBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.tabBar.mas_top);
make.left.equalTo(self.tabBar.mas_left);
make.bottom.equalTo(self.tabBar.mas_bottom);
make.right.equalTo(self.tabBar.mas_right);
}];
}
结果是程序刚一启动,就崩溃了,跑出错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot modify constraints for UITabBar managed by a controller'
那么,为什么会出现这种错误呢?
因为Autolayout只能对uiview和它的子类起作用。UIBarButtonItem不继承自UIView,Autolayout对UIBarButtonItem不起作用。
解决办法:
第一种方法:
- (void)setupTabbar{
WWTabBar *customTabBar = [[WWTabBaralloc]init];
customTabBar.backgroundColor = [UIColorwhiteColor];
customTabBar.delegate =self;
customTabBar.frame =self.tabBar.bounds;
[self.tabBaraddSubview:customTabBar];
self.customTabBar = customTabBar;
customTabBar.autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
}
- (void)changeRotate:(NSNotification*)noti {
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait
|| [[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"竖屏");
} else {
NSLog(@"横屏");
}
}
好了,到这就就说完了,小伙伴们赶快试试吧。
- reason: 'Cannot modify constraints for UITabBar managed by a controller'
- iOS 【错误:'Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'】
- 解决Warning: Cannot modify header information - headers already sent by ......
- 解决Warning: Cannot modify header information - headers already sent by
- php错误"Cannot modify header information - headers already sent by"
- php错误"Cannot modify header information - headers already sent by"
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Warning: Cannot modify header information - headers already sent by
- Cannot modify header information – headers already sent by解决
- 解决cannot modify header information - headers already sent by (......)。
- Cannot modify header information - headers already sent by
- 解决cannot modify header information - headers already sent by (......)。
- Android短信验证(手机号注册,绑定手机号获取验证码)实例
- Android Studio 通过 gradle 构建 jar
- 拖拽最简单的实现方式[JQuery实现]
- 图像处理控件Graphics Mill for .NET更新至v9.1.28,支持PSD
- Gym
- reason: 'Cannot modify constraints for UITabBar managed by a controller'
- android Html.fromHtml font 标签支持设置字体大小和颜色
- (数学水题)Codeforces A. Kirill And The Game
- 第十三章 多种I/O复用
- .NET Core 2将Visual Basic带到了Linux和macOS平台
- string转char*
- Kafka 安装与配置
- SQL语言第一节:SQL语言分类
- Docker入门,从0到1