ios 7을 지원하는 Landscape(가로) 어플리케이션을 제작할 때 고려할 사항

13019 단어 SwiftiOS

Device Orientation만 Landscape로 설정하면 Landscape에서 시작하는 응용 프로그램을 만들 수 있습니다.당사그림책 응용 프로그램 PIBO(PIBO)에도 이러한 설정이 있으나ios7을 처리하기 전에 화면 사이즈를 확보하는 데 주의해야 합니다.

ios7의 주의점


・self.view.frame.크기 반환 세로 크기
・UIScreen.mainScreen().bounds도 세로 크기로 되돌아오기
・viewDidLoad 및 viewWillApper의 selfview.bounds.크기도 세로 크기로 되돌려줍니다
• Portrait에서 Landscape로 회전할 때 self.view.bounds.사이즈는 정확한 사이즈를 얻을 수 있습니다.

결론 ios7 이전에는 다음의 screenSize()를 사용하는 것이 좋습니다.

    func screenSize() -> 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
    }

ios7과 ios8의 정시와 화면 사이즈가 다르다


ios7에서 가로로 시작할 때


* 위의 screenSize ()는 Correct screenSize ()입니다.
viewDidLoad
----------------
 frame                        w320.0 h:568.0
 bounds                       w320.0 h:568.0
 UIScreen.mainScreen().bounds w320.0 h:568.0
 Correct screenSize()         w568.0 h:320.0
----------------

viewWillAppear
----------------
 frame                        w320.0 h:568.0
 bounds                       w320.0 h:568.0
 UIScreen.mainScreen().bounds w320.0 h:568.0
 Correct screenSize()         w568.0 h:320.0
----------------

viewDidLayoutSubviews
----------------
 frame                        w320.0 h:568.0
 bounds                       w568.0 h:320.0
 UIScreen.mainScreen().bounds w320.0 h:568.0
 Correct screenSize()         w568.0 h:320.0
----------------

viewDidAppear
----------------
 frame                        w320.0 h:568.0
 bounds                       w568.0 h:320.0
 UIScreen.mainScreen().bounds w320.0 h:568.0
 Correct screenSize()         w568.0 h:320.0
----------------

ios8에서 가로로 시작할 때

viewDidLoad
----------------
 frame                        w568.0 h:320.0
 bounds                       w568.0 h:320.0
 UIScreen.mainScreen().bounds w568.0 h:320.0
 Correct screenSize()         w568.0 h:320.0
----------------

viewWillAppear
----------------
 frame                        w568.0 h:320.0
 bounds                       w568.0 h:320.0
 UIScreen.mainScreen().bounds w568.0 h:320.0
 Correct screenSize()         w568.0 h:320.0
----------------

viewDidLayoutSubviews
----------------
 frame                        w568.0 h:320.0
 bounds                       w568.0 h:320.0
 UIScreen.mainScreen().bounds w568.0 h:320.0
 Correct screenSize()         w568.0 h:320.0
----------------

viewDidAppear
----------------
 frame                        w568.0 h:320.0
 bounds                       w568.0 h:320.0
 UIScreen.mainScreen().bounds w568.0 h:320.0
 Correct screenSize()         w568.0 h:320.0
----------------

테스트 코드


다음 코드로 상술한 결과를 시도할 수 있습니다.
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        printSizes("viewDidLoad")
    }

    override func viewWillAppear(animated: Bool) {
        printSizes("viewWillAppear")
    }

    override func viewDidLayoutSubviews() {
        printSizes("viewDidLayoutSubviews")
    }

    override func viewDidAppear(animated: Bool) {
        printSizes("viewDidAppear")
    }


    override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
        if UIDevice.currentDevice().orientation.isLandscape {
            printSizes("isLandscape")
        }else if UIDevice.currentDevice().orientation.isPortrait {
            printSizes("isPortrait")
        }
    }

    func printSizes(s: String){
        println(s)
        println("----------------")
        println(" frame                        w\(self.view.frame.width) h:\(self.view.frame.height)")
        println(" bounds                       w\(self.view.bounds.width) h:\(self.view.bounds.height)")
        println(" UIScreen.mainScreen().bounds w\(UIScreen.mainScreen().bounds.width) h:\(UIScreen.mainScreen().bounds.height)")
        println(" Correct screenSize()         w\(self.screenSize().width) h:\(self.screenSize().height)")
        println("----------------")
        println()
    }

    func screenSize() -> 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
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

좋은 웹페이지 즐겨찾기