Help us understand the problem. What is going on with this article?

iPhoneXのViewでの位置の取得方法まとめ

More than 1 year has passed since last update.

取得するタイミングに注意

詳しくはこちらの記事に書いてあったが、viewWillLayoutSubviews()以降に呼ばれるメソッドの中でしかSafeAreaの値は取得できないので注意。
上の記事にはviewDidLoad()などが呼ばれる順番も書いてあった。

SafeAreaの座標の取得方法

SafeAreaは上下に被らない長方形の所の話
image.png

            //safeAreaFrameが上の青い部分のCGRect.
            let safeAreaFrame = self.view.safeAreaLayoutGuide.layoutFrame
            let safeAreaTop = safeAreaFrame.origin.y
            let safeAreaBottom = safeAreaFrame.origin.y + safeAreaFrame.height
            let safeAreaRight = safeAreaFrame.origin.x
            let safeAreaLeft = safeAreaFrame.origin.x + safeAreaFrame.width

SafeArea外の画面を覆う四角の座標取得方法

iPhoneXはいびつな画面の形をしているが、それを覆うような長方形viewをうまく配置すると考えると話は楽になる

            //overViewFrameが上からかぶせる長方形のCGRect
            let overViewFrame = self.view.safeAreaLayoutGuide.owningView!.frame
            let overViewTop = overViewFrame.origin.y
            let overViewBottom = overViewFrame.origin.y + overViewFrame.height
            let overViewRight = overViewFrame.origin.x
            let overViewLeft = overViewFrame.origin.x + overViewFrame.width

あとはうまく使おう

ここさえ取れればいくらでも自作でnavigationBarやらを作れる気がしたのでやってみよう。
あとでまたnavigationBarを作ったら記事書いてここに載せます。

追記: かけたー
iPhoneXでも他でも使える"上に表示するバー"(NavigationBar)を作ろう

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away