问题描述
由于的UIBarButtonItem
不继承的UIView
,这是不可能获取像它的<$ c中的正常特性$ C>架。
Since UIBarButtonItem
doesn't subclass UIView
, it's impossible to get at the normal characteristics like its frame
.
做到这一点的方法之一是 [barButtonItem valueForKey:@视图]
One way to do this is [barButtonItem valueForKey:@"view"]
这完美的作品,并允许您添加GestureRecognizer(例如)到底层的UIView
。
This works perfectly, and allows you to add a GestureRecognizer (for instance) to the underlying UIView
.
不过,这是一个私人的UIKit
API违规?
However, is this a private UIKit
API violation?
推荐答案
这是不是在验证立即拒绝而言私有的,但它是足够的私人被认为是脆弱的(也就是,新的iOS版本,可以打破现有的应用程序中这是一个使用code中的应用程序商店)。
This is not private in terms of immediate rejection upon validation, but it's private enough to be considered fragile (that is, new iOS version can break your existing app in the app store that's using the code).
我可以说,一个类似code(获取通过KVC UIToolbar的backgroundView伊瓦尔)已通过应用程序商店验证和生产中正在使用。
I can say, that a similar code (fetching backgroundView ivar of UIToolbar via KVC) has passed app store validation and is being used in production.
在可能的坏事情况下,必须在包装方法 @try {...} @catch
,让你拦截KVC在新版iOS版本可能失败
In case of possible bad things, you must wrap the method in @try { ... } @catch
, so that you intercept KVC possibly failing in newer iOS release.
这篇关于使用`valueForKey`访问视图的UIBarButtonItem,私有API违规?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!