2016-03-22 4 views
2

iPhoneを回転できる方向を制限したとてもシンプルなアプリを作成しました。rawValueプロパティはどこですか?

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 

    return UIInterfaceOrientationMask(rawValue: (UIInterfaceOrientationMask.Portrait.rawValue | UIInterfaceOrientationMask.LandscapeLeft.rawValue)) 

} 

そして、私はUIInterfaceOrientationMaskの実装を見ると:のViewControllerでは、私は次のようにメソッドをオーバーライドしsupportedInterfaceOrientations

public struct UIInterfaceOrientationMask : OptionSetType { 
    public init(rawValue: UInt) 

    public static var Portrait: UIInterfaceOrientationMask { get } 
    public static var LandscapeLeft: UIInterfaceOrientationMask { get } 
    public static var LandscapeRight: UIInterfaceOrientationMask { get } 
    public static var PortraitUpsideDown: UIInterfaceOrientationMask { get } 
    public static var Landscape: UIInterfaceOrientationMask { get } 
    public static var All: UIInterfaceOrientationMask { get } 
    public static var AllButUpsideDown: UIInterfaceOrientationMask { get } 
} 

私は例PortraitプロパティのプロパティrawValue上を見つけることができません。どこrawValueから来る?

答えて

1

ちょうどこの戻る:ちょうど戻ってそれの元の値に変換するために、生の値を取得にはポイントがありません

return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.LandscapeLeft] 

を! :)

+0

私は何かが足りないかもしれませんが、 '[UIInterfaceOrientationMask]'ではなく 'UIInterfaceOrientationMask'型のものを返す必要はありませんか? –

+0

UIInterfaceOrientationMask型のものを返しています。この魔法は、ArrayLiteralConvertibleであるOptionSetTypeによって処理されます。配列リテラルの変換では、メンバーはセットのように扱い、それらを適切な型の適切な値に結合します。 Google OptionSetTypeを使用して、ネット上で利用可能なチュートリアルの一部を読んでください。 –

関連する問題