- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
从 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 上,无论 animated
是 true
还是 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/
我是一名优秀的程序员,十分优秀!