我试图在函数外访问 view.frame.size.height
和 view.frame.size.width
,但我无法访问。有什么解决方法吗?
我试过了,但是没用-
var screenBound = UIScreen.mainScreen().bounds
var screenSize = screenBound.size
var screenWidth = screenSize.width
var screenHeight = screenSize.height
Xcode 给了我一个错误 - 实例成员“screenbound”不能用于类型“ViewController”
我只能在创建的函数中使用 self.view.frame.size.height/.width
。但是我想在函数之外使用它。提前致谢。
最佳答案
我不确定你到底想做什么,但你不能把它放在全局级别(即在“类 ViewController...”之上):
让 screenWidth = UIScreen.mainScreen().bounds.size.width
让 screenHeight = UIScreen.mainScreen().bounds.size.height
然后您可以在项目的任何地方访问这些。
关于ios - 如何在函数外获取 View 的尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36556903/