0

Is using UIScreen.mainScreen().bounds.size.height to position or size elements in my layout based on device size an acceptable thing to do? Or will this kind of thing have me hauled off to a infinite loop cubical farm for a thrashing?

4

1 回答 1

0

Yes it is acceptable, however you do not want to call UIScreen.mainScreen() more than once or twice, as it's a very slow function.

So keep a copy of the result cached like so:

var mainScreen: UIScreen

override init() {
  self.mainScreen = UIScreen.mainScreen()
}

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
  let height = self.mainScreen.bounds.size.height;

  // do stuff with height
}
于 2015-02-01T01:36:36.427 回答