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

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

[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

関連記事

[Swift] UINavigationControllerで戻るイベントを取得する

UINavigationController UINavigationControllerを使用し

記事を読む

no image

爆走中!

挫折街道爆走中です! が! 迷走中でもあるわけです、はい。 そんな中で、迷走するに至った訳

記事を読む

App開発をはじめてみました。

はじめてみたはいいものの、右も左もわからず、書籍を読みあさり、ネットを徘徊し、いろんなことを調べ上げ

記事を読む

[Swift] CoreDataを使ってみる

SwiftでCoreData 今回はSwiftでCoreDataを使ってみます。 Xcodeプロ

記事を読む

iPhoneApp WorkManager公開されました!

きっとリジェクトされるんだろうなと思いながら申請を出して1週間。 本日、公開のメールが届きまし

記事を読む

[Swift] CoreDataのテーブルからデータ件数を取得する

件数を取得する fetchResultsControllerなどを使わず、直接テーブルのデータ件数

記事を読む

no image

OSSの使い方がわからない・・・。

チュートリアル系の、storyboradでview controllerを置いて画面遷移を設定してっ

記事を読む

Xcode5のstoryboard内でUIKeyCommandエラーの対処法

既存のプロジェクトからstoryboardにあるオブジェクトをコピペして、新規プロジェクトに貼付けた

記事を読む

[Objective-C] 文字列操作の便利Tips

Tipsいろいろ 先日の投稿 共通関数をまとめたクラスを作ろう!の流れで、文字列を操作するときに便

記事を読む

備忘録的メモ

Xcode5にアップデートして、とりあえずアプリを走らせてみたらナビゲーションバーがかぶってる・・・

記事を読む

ad

Message

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

ad

[PHP] curl転送してみる(googleに)

curlでgoogle画像検索APIにアクセスしてみます。 cu

[PHP] PDOでMySQLの接続確認をする

PDO PHPでMySQLに接続する際には、mysql_connec

[PHP] ランダムな英数字を生成する

便利系メソッド 今回はPHPでランダムな英数字を作成してみます。

[Swift] プロパティリスト(plist)の値を取得

plistからデータを取得してみます。 こちらのエントリーも参考にし

[Swift] Asset Catalogについて

XCode5から追加されたAsset Catalog。 いままで標準

→もっと見る

  • 1978年の七夕生まれ。 25才でweb業界の門を叩き、28才でフリーランスに。 現在は、フリーランスでマークアップ中心に、wordpressのカスタマイズやデザインをしております。 また、iPhoneアプリの開発もしております。

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
PAGE TOP ↑

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