最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[未解决]自定义swift中UITabBarController的高度

Swift crifan 3801浏览 0评论
[背景]
之前:
已经实现了,把tab加到当前页面了
但是虽然给定了对应的显示区域,只是一个页面的下半部分,但是结果tab显示出来并没有按照对应的区域去显示。
希望希望:
UITabBarController的高度,可以自定义,保证在某个范围内去显示。
[折腾过程]
1.也试了试,单独加个UIView:
        let tabSubView = UIView(frame: CGRectMake(
0,
//statusView.frame.height + ownedSchoolCoinBgView.frame.height + tabbgView.frame.height,
0,
self.view.frame.width,
self.view.bounds.size.height – ownedSchoolCoinBgView.frame.origin.y
))print(“tabSubView.frame=\(tabSubView.frame)”)

let recordTabBarView = UITabBarController()
//let allRecordTab = AllRecordTabViewController(nibName: “全部记录”, bundle: nil)
let allRecordTab = AllRecordTabViewController()
//let incomeRecordTab = IncomeRecordTabViewController(nibName: “收入记录”, bundle: nil)
let incomeRecordTab = IncomeRecordTabViewController()
//let expenseRecordTab = ExpenseRecordTabViewController(nibName: “支出记录”, bundle: nil)
let expenseRecordTab = ExpenseRecordTabViewController()
let tabControllers = [allRecordTab, incomeRecordTab, expenseRecordTab]

recordTabBarView.viewControllers = tabControllers
recordTabBarView.selectedIndex = 2

//self.addChildViewController(recordTabBarView)
tabSubView.addSubview(recordTabBarView.view)

        self.view.addSubview(tabSubView)
结果问题依旧。
2.搜:
uitabbarcontroller height
参考:
reduce height of UITabBarController – Google 网上论坛
去搜索:
swift UITabBar
参考:
没用。
搜:
swift sizeThatFits
参考:
算了,自己随便试试。
但是之前帖子中,给出的只是:
定制tabbar的高度,而不是整个view的高度啊。。。
3.搜:
uitabbarcontroller customize view height
参考:
然后用了如下代码:
        recordTabBarView.viewControllers = tabControllers
recordTabBarView.selectedIndex = 2

var tabFrame:CGRect = recordTabBarView.tabBar.frame
print(“origin tabFrame=\(tabFrame)”)
tabFrame.size.height -= 60
recordTabBarView.tabBar.frame = tabFrame
print(“new tabFrame=\(recordTabBarView.tabBar.frame)”)

//self.addChildViewController(recordTabBarView)

        tabSubView.addSubview(recordTabBarView.view)
得到很诡异的效果:

got abnormal tab height

4.突然想起来:
好像对于此处的UITabBarController来说:
此处的tabbar是控制底部的tab的
而此处想要改变的,上面的显示的内容的view的大小,降低成本高度,应该去找,UITabBarController的每个tab的view才对。
不过也还是先再去试试,降低y值试试。
结果:
        var tabFrame:CGRect = recordTabBarView.tabBar.frame
print(“origin tabFrame=\(tabFrame)”)
tabFrame.size.height -= 60
tabFrame.origin.y -= 20
recordTabBarView.tabBar.frame= tabFrame
        print(“new tabFrame=\(recordTabBarView.tabBar.frame)”)
效果:
reduce y height for tab
还是没用。
5.参考:
看看是否有autoresize的属性
结果遇到了:
6.参考:
去搜搜:
swift UITransitionView
参考:
想要尝试去修改高度:
        recordTabBarView.transitionCoordinator()?.containerView().frame.height = 60
结果是只读的,不允许修改:
Cannot assign to property: ‘height’ is a get-only property
才知道:
原来UITransitionView是非公开的api,所以网上找不到官方文档。
7.看了:
感觉是:
应该单独创建一个 tab view controlller
然后加入到此处作为sub view
-》或许显示大小,就可以自动适配了
-》就不会把整个页面大小都占用了。。。
8.代码:
        var tabFrame:CGRect = recordTabBarView.tabBar.frame
print(“origin tabFrame=\(tabFrame)”)
tabFrame.size.height -= 60
tabFrame.origin.y -= 20
recordTabBarView.tabBar.frame = tabFrame
print(“new1 tabFrame=\(recordTabBarView.tabBar.frame)”)

//recordTabBarView.transitionCoordinator()?.containerView().frame.height = 60
//recordTabBarView.tabBar.frame.height -= 60
recordTabBarView.tabBar.frame= tabSubView.frame

        print(“new2 tabFrame=\(recordTabBarView.tabBar.frame)”)
对应log是:
tabSubView.frame=(0.0, 0.0, 375.0, 603.0)
origin tabFrame=(0.0, 618.0, 375.0, 49.0)
new1 tabFrame=(0.0, 587.0, 375.0, 11.0)
new2 tabFrame=(0.0, 0.0, 375.0, 603.0)
效果是:

tab bar move to top

有点意思。
但是改来改去,都还是没发实现:
单独在下面半部分显示。。
9.下载:
的代码,结果也看不懂。。
10.搜:
swift subclass tab view
算了,还是先从:
基本的,如何代码上实现,tab的写法,去慢慢学习和了解tab的用法。
有空再继续折腾。

转载请注明:在路上 » [未解决]自定义swift中UITabBarController的高度

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
86 queries in 0.171 seconds, using 22.16MB memory