[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
関連記事
-
-
[iPhone App]WorkManager アップデートしました。
Processing For App Storeでやきもきした僕です。こんにちわ。 今
-
-
[Swift] UINavigationControllerで戻るイベントを取得する
UINavigationController UINavigationControllerを使用し
-
-
[Objective-C] no architectures to compile for … のコンパイルエラーについて
起動したプロジェクトでコンパイルエラーが出ました。 no architectures to com
-
-
[Objective-C] 共通関数をまとめたクラスを作ろう!
共通クラスとは? アプリを作っていると「この処理何回も書いてるなー」ということが多々あると思います
-
-
[Objective-C] iPhoneアプリからのメーラー起動
今回はiPhoneアプリからメーラーを起動する処理を紹介します。 メーラー起動のコントローラー
-
-
[Swift] CoreDataを使ってみる
SwiftでCoreData 今回はSwiftでCoreDataを使ってみます。 Xcodeプロ
-
-
[Swift] UITabBarControllerでタブ選択時のイベントを取得する
UITabBarController タブを使った画面を作成する場合はUITabBarContro
-
-
NSDateを5分刻み・15分刻みで丸める
NsDateを初期値としてUIDatePicker等に設定する場合、日付の丸め処理が必要になるのでメ
-
-
[Swift] Asset Catalogについて
XCode5から追加されたAsset Catalog。 いままで標準のImages.xcasset