の向きを(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
条件付きで設定できます。このようなものはきれいではありませんが、機能します:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(orientation == 0) //Default orientation
//UI is in Default (Portrait) -- this is really a just a failsafe.
else if(orientation == UIInterfaceOrientationPortrait)
//Do something if the orientation is in Portrait
else if(orientation == UIInterfaceOrientationLandscapeLeft)
// Do something if Left
else if(orientation == UIInterfaceOrientationLandscapeRight)
//Do something if right
それ以外の場合、この投稿はあなたがやろうとしていることとかなり関連しているようです:
IPad の横向きでのアプリケーションの起動
提案2
以下を使用して、デバイスの向きを検出するメソッド (つまり、「deviceInfo」) を持つクラスを作成できます。
UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation])
と
UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]statusBarOrientation])
必要なストレッチ係数/寸法/測定値を保存することもできます。次に、view
メソッド-(id)initWithFrame:(CGRect)frame
を呼び出して方向を確認できます (つまりdeviceInfo.isLandscape?
)。次に、あなたが に等しいと設定view
しautoresizingMask
ます UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
。次に、必要なディメンションに等しく-(void)layoutSubviews
設定しview.frame
ます。
CGRectMake(x-origin, y-origin, width, height);
現在の向きを取得するためのリファレンスは次のとおりです。
http://www.ddeville.me/2011/01/getting-the-interface-orientation-in-ios/
ビュー フレームの寸法を変更するのは比較的簡単で、Apple のドキュメントや簡単なグーグル検索で見つけることができます。