LoginSignup
3
3

More than 5 years have passed since last update.

【iOS画面回転制御】Universalアプリで、iPhoneかiPadなのかで回転OK/NGを決めたい場合

Posted at

拙作、"ICF inputter" http://bit.ly/ICFinputteriOS
これをUniversal対応にすべくアクションしておりました。
※Androidも開発しました… http://bit.ly/ICFinputAndr

このソフトは、「簡易な方法で医療記録をつける」ことに主眼をおいたもので
たとえば在宅医療の患者宅で、パッとメモ程度の記録を残して
後でevernoteなどに連携して編集することを想定しています。

なので、「使い勝手の良さ」をとにかく重要視したかったわけです。
デバイスごとのボタン配置・ボタンの大きさ=フォントの大きさの指定は必須。
私は13個あるパーツの座標の配置とフォント指定をひたすらトライ&エラーしました。

ただ、このソフトはiPhoneのLandscapeポジションで使うことはないと思われます。
それ故
・iPhoneはホームボタンが下のときのPortraitのみでOK.
 →回転禁止にしたい。
・iPadはLandspaceにしたほうが使い勝手がよい&Portraitでも使うことが想定されたので
 →回転OKにしたい。

なのに、一部条件のときに
-(BOOL)shouldAutorotate; でNOにしても

画 面 が 廻 る
ので困っていたところ。。。
cccookieさんの記事が参考になりました。ありがとうございます。

cccokkieさんは別に親クラスを作っていらっしゃいますが、私はViewContoller.mのところでどうにもならなくて困っていたため、


AppDelegate.h


//邪魔にならないところにつけたす。回転制御。
@interface UINavigationController (rotateControl)
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end

AppDelegate.m

#import "AppDelegate.h"

@implementation UINavigationController (rotateControl)

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.visibleViewController supportedInterfaceOrientations];
}

- (BOOL)shouldAutorotate
{
    return [self.visibleViewController shouldAutorotate];
}
@end

を追記したところ、ViewContoroller.mで

ViewContoroller.mより

-(BOOL)shouldAutorotate{
    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    if(appDelegate.iPad == 1){
        return YES;
    }else{
        return NO;
    }
}

としていたコードが動くようになりました。

お困りの方の一助となれば幸いです。

3
3
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3