我正在尝试访问某个函数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类...”上方):
let screenWidth = UIScreen.mainScreen().bounds.size.width let screenHeight = UIScreen.mainScreen().bounds.size.height
然后,您可以在项目中的任何位置访问它们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句