How to get height of topLayoutGuide?

后端 未结 3 551
太阳男子
太阳男子 2021-02-01 15:23
 moviePlayer = MPMoviePlayerController(contentURL: url)
 moviePlayer.view.frame = CGRect(x: 0, y:{layoutguide.height}, width:
 self.view.frame.width, height: 300)
 self.         


        
3条回答
  •  北海茫月
    2021-02-01 15:47

    You can get the topLayoutGuide value as its length property:

    // Inside your viewController
    self.topLayoutGuide.length
    

    Since it is a single value (i.e.: it does not have a height and width) they just called it length. Same holds for bottomLayoutGuide.

    Hope this helps

    One more thing to mention, in the apple doc for this property:

    // As a courtesy when not using auto layout, this value is safe to refer to in -viewDidLayoutSubviews, or in -layoutSubviews after calling super

    Use this property in these two functions will get you the accurate value, since the layout has been initialized. If you use it in the viewDidLoad function, this property will be 0.

提交回复
热议问题