如何快速获取rightbarbuttonItem的框架?我发现了这一点:UIBarButtonItem:如何找到它的框架?但是它说不能将NSString转换为UIView,或者不能将NSString转换为String:
let str : NSString = "view" //or type String let theView : UIView = self.navigationItem.rightBarButtonItem!.valueForKey("view")//or 'str'
目标是删除rightBarButtonItem,添加一个imageView,然后使用fadeOut效果对其进行移动。
谢谢
您应该像这样尝试:
var barButtonItem = self.navigationItem.rightBarButtonItem! var buttonItemView = barButtonItem.valueForKey("view") var buttonItemSize = buttonItemView?.size
编辑(快速3):
var barButtonItem = self.navigationItem.rightBarButtonItem! let buttonItemView = barButtonItem.value(forKey: "view") as? UIView var buttonItemSize = buttonItemView?.size