gpt4 book ai didi

ios - 设置 UIBarButtonItem 动画不适用于 iOS 11

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:56 25 4
gpt4 key购买 nike

从 iOS 11 开始,animated 参数似乎在 setLeftBarButtonItems( _, animated: Bool) 中被忽略了,setRightBarButtonItems(_, animated:)setLeftBarButton(_, animated:)setRightBarButton(_, animated:) 方法。

我为 UIViewController 子类编写了这个简单的代码:

override func viewDidLoad() {
super.viewDidLoad()

let rightButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(changeRightBarButtonItem(_:)))
navigationItem.rightBarButtonItem = rightButton
}

@objc
func changeRightBarButtonItem(_ sender: Any) {
let newRightButton = UIBarButtonItem(title: "Cancel", style: .plain,
target: self, action: #selector(changeRightBarButtonItem(_:)))
navigationItem.setRightBarButtonItems([newRightButton], animated: true)
}

这在 iOS 10 上按预期运行,但在 iOS 11 上,无论 animatedtrue 还是 false 都没有区别。

它似乎是 iOS 11,但也许我漏掉了什么。有什么提示让它工作吗?即使是解决方法也会很有趣。

最佳答案

这似乎是 iOS 11 导航栏实现中的错误。

引用:

这些 setLeftBarButtonItem:animated:setRightBarButtonItem:animated:setLeftBarButtonItems:animated:setRightBarButtonItems:animated: code> 根本不是真正的动画项目。

我认为这也是一个 iOS 11 实现错误,因为在来自这些 mtehods 的调用链中最终调用 updateTopNavigationItemAnimated:,但是,当前的实现是这样的。

-[_UINavigationBarVisualProviderModernIOS updateTopNavigationItemAnimated:]:
0000000000be5708 push rbp
; Objective C Implementation defined at 0x13ff050 (instance method), DATA XREF=0x13ff050
0000000000be5709 mov rbp, rsp
0000000000be570c mov rsi, qword [0x147f030]
; @selector(setupTopNavigationItem), argument "selector" for method _objc_msgSend
0000000000be5713 pop rbp
0000000000be5714 jmp qword [_objc_msgSend_11195c8]
; _objc_msgSend

显然,此方法会忽略给定的动画参数并简单地调用不带任何参数的 setupTopNavigationItem。因此,此时忽略动画标志。

由于这种实现,在某些情况下,UIBarButton 有时似乎会保持按下状态。

来源:https://gist.github.com/niw/569b49648fcab22124e1d12c195fe595

关于ios - 设置 UIBarButtonItem 动画不适用于 iOS 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46920720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com