[Swift] スクリーンサイズを取得する
公開日:
:
iPhone App 開発, Swift
Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
スクリーンサイズを取得
iPhoneの幅と高さを取得する関数を紹介します。
iOS8から画面の傾きでのUIScreenの幅・高さが反映されるようになったのでiOSのバージョンにより判断が必要になりました。
func getScreenSize() -> CGSize {
let screenSize = UIScreen.mainScreen().bounds.size;
if NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1
&& UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation) {
return CGSizeMake(screenSize.height, screenSize.width)
}
return screenSize
}
2行目でスクリーンサイズを取得。
3・4行目でiOSのバージョンと画面の傾きを判断します。
戻り値はCGSizeです。
高さを取得する場合はCGSize.height。
幅を取得する場合はCGSize.width。
ad
関連記事
-
-
[Objective-C] iPhoneアプリからのメーラー起動
今回はiPhoneアプリからメーラーを起動する処理を紹介します。 メーラー起動のコントローラー
-
-
[Swift] Asset Catalogについて
XCode5から追加されたAsset Catalog。 いままで標準のImages.xcasset
-
-
[Objective-C] 文字列操作の便利Tips
Tipsいろいろ 先日の投稿 共通関数をまとめたクラスを作ろう!の流れで、文字列を操作するときに便
-
-
[iPhone App]WorkManager アップデートしました。
Processing For App Storeでやきもきした僕です。こんにちわ。 今
-
-
[Objective-C] UINavigationControllerのセグエを使って画面遷移をする
画面遷移の実装 今回はUINavigationControllerを使って画面遷移をしたいと思いま
-
-
[Swift] UITabBarControllerでタブ選択時のイベントを取得する
UITabBarController タブを使った画面を作成する場合はUITabBarContro
-
-
小さなことからコツコツと
これまでHTMLとCSSだけで生きてきただけあって、プログラム言語がいまいちわからない。 Mo
-
-
TabBarControllerとNavigationControllerのボタン追加
TabBarとNavigationを同時に使っているViewControllerの場合、naviga
-
-
Xcode5のstoryboard内でUIKeyCommandエラーの対処法
既存のプロジェクトからstoryboardにあるオブジェクトをコピペして、新規プロジェクトに貼付けた