【发布时间】:2015-12-07 23:41:04
【问题描述】:
我正在开发一个应用程序,该应用程序的视图根据其屏幕尺寸定位在不同的位置。大小取决于设备。我选择了 iPhone 5S 的尺寸。我的应用程序将在 iPad 上运行。 看看 Swift 代码怎么样:
class Main: UIViewController {
@IBOutlet var viewRect: UIView!
let DeviceHeigth:CGFloat = 1136 / 2
let DeviceWith:CGFloat = 640 / 2
override func viewDidLoad() {
super.viewDidLoad()
calcviewRectViewInit()
}
func calcviewRectViewInit(){
let space:CGFloat = 40
var frame: CGRect = viewRect.frame
frame.size.height = DeviceHeigth
frame.size.width = DeviceWith
frame.origin = CGPoint(x: toolView.frame.width + space, y: space)
viewRect.frame = frame
}
当您开始时,Rect 视图不会按代码定位在大小和位置中。 viewDidLoad 不会在运行时重绘视图。
我的问题是:启动应用时如何重绘视图(viewRect)?
【问题讨论】:
-
将
DeviceWidth替换为UIScreen.mainScreen().bounds.width和DeviceHeight替换为UIScreen.mainScreen().bounds.height怎么样?
标签: swift uiview swift2 swift2.1