GSe*_*rjo 5 xcode uitoolbar swift ios11
找不到我在创建工具栏时出错的地方.
1 - 通过代码创建,请参阅下文
let toolBar = UIToolbar()
var items = [UIBarButtonItem]()
toolBar.barTintColor = theme.barTintColor
let share = UIBarButtonItem(barButtonSystemItem: .action, target: nil, action: nil)
items.append(share)
items.append(UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil))
let trash = UIBarButtonItem(barButtonSystemItem: .trash, target: nil, action: nil)
self.view.addSubview(toolBar)
toolBar.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
let guide = self.view.safeAreaLayoutGuide
toolBar.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
toolBar.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
toolBar.bottomAnchor.constraint(equalTo: guide.bottomAnchor).isActive = true
//toolBar.heightAnchor.constraint(equalToConstant: 44).isActive = true
}
Run Code Online (Sandbox Code Playgroud)
2 - 通过设计师添加
看起来它们具有不同的高度,因此在UIBarButtonItems之上有不同的缩进
编辑0:在故事板中,toolbar 2默认配置
编辑1:可视化调试器显示_UIToolbarContentView从toolbar 2高处_UIToolbarContentView toolbar 1开始5px.
<_UIToolbarContentView: 0x153e13190; frame = (0 0; 375 49); autoresize = W+H; layer = <CALayer: 0x1d0236d80>>
Printing description of $28:
<_UIToolbarContentView: 0x15b9f08d0; frame = (0 0; 375 44); autoresize = W+H; layer = <CALayer: 0x1d522af00>>
Run Code Online (Sandbox Code Playgroud)
编辑2:iPhone X上的这种奇怪的行为,在iPhone 6上都很好.
解决方法:如果是iPhone X,请添加此hack
toolBar.heightAnchor.constraint(equalToConstant: 49)
| 归档时间: |
|
| 查看次数: |
254 次 |
| 最近记录: |