本文介绍了在Swift中获取UIBarButtonItem的框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在swift中获取rightbarbuttonItem的框架?我发现了这个:但是它说无法将NSString转换为UIView,或者无法将NSString转换为String:

how could I get the frame of a rightbarbuttonItem in swift? I found this : UIBarButtonItem: How can I find its frame? but it says cannot convert NSString to UIView, or cannot convert NSString to String :

let str : NSString = "view" //or type String
let theView : UIView = self.navigationItem.rightBarButtonItem!.valueForKey("view")//or 'str'

目标是删除rightBarButtonItem,改为添加imageView,并使用fadeOut效果移动它。

The goal is to remove the rightBarButtonItem, add an imageView instead, and move it with a fadeOut effect.

谢谢

推荐答案

您应该尝试:

var barButtonItem = self.navigationItem.rightBarButtonItem!
var buttonItemView = barButtonItem.valueForKey("view")

var buttonItemSize = buttonItemView?.size

编辑(Swift 3):

var barButtonItem = self.navigationItem.rightBarButtonItem!
let buttonItemView = barButtonItem.value(forKey: "view") as? UIView
var buttonItemSize = buttonItemView?.size

这篇关于在Swift中获取UIBarButtonItem的框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:58