お願いします。ViewDidLoadのiphoneデバイスの現在の向き
-(void) getCurrentOrientation{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation == UIInterfaceOrientationPortrait){
NSLog(@"portrait");
} else if(orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"LandscapeRight");
} else if(orientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"LandscapeLeft");
}
}
が、私はこのgetCurrentOrientationは、のviewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
[self getCurrentOrientation];
}
のNSLogが空であるを投げる呼び出す:私は、メソッドを持っています。どうしましたか ? 私もお試しください
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait)) {
NSLog(@"portrait");
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
NSLog(@"LandscapeRight");
}
}
しかし、そのvarintも空です。
私はどのオリエントユーザーがAPPを起動するのか知っておく必要があります。
私に助言をしてください。
ありがとうございます。しかし、私がLANDSCAPEモードでシミュレータを実行すると、NSlogはPORTRAITを出力します。したがって、実際のデバイスでの作業を修正するかどうかはわかりません –
更新された回答を確認してください –
プロジェクト - ターゲット - 概要 - サポートされているデバイスオリエンテーションのみランドスケープで選択します。しかし、あなたの関数Nslogの出力ポートレートでsumulatorでappを実行すると、なぜ私は頼りにしてはいけないのか?私はちょうどオリエンテーションのユーザーがアプリを実行する知っている必要があります。 –