2012年8月4日土曜日

【iPhone&iPad】デバイスの向きと回転した際の対応方法


【ViewController.h】

@interface ViewController : UIViewController<ModalViewDelegate>{
    IBOutlet UIButton *expBtn;
    IBOutlet UIButton *demoBtn;
    IBOutlet UIView *mainContentView;
}





【ViewController.m】

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    mainContentView.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
    
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    //デバイス回転通知
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didRotate:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
}

//デバイス回転通知時の命令
- (void) didRotate:(NSNotification *)notification {
    mainContentView.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
}


0 件のコメント:

コメントを投稿