ユーザーがアプリを起動したときに画像を表示したい。この画像は20秒間表示されています。
ユーザーが横向きでアプリを起動したときに、アプリが横向きのままになる機能が欲しいのですが。また、ユーザーがPortraitでアプリを起動すると、アプリはPortraitのままになります。
Appdelegateでこれを構成するのに本当に苦労したので、この画像を表示するために別のビューコントローラーを作成しました。タイマーが終了したら、回転を有効にする次のビューに移動します。
では、どうすればiPadのUIを一時的にロックできますか?
編集:
Appdelegateの後の最初のViewcontrollerのviewDidLoad内に方向チェックを実装することで、これを修正しました。すべての向きについて、値を保存しました。shouldAutorotateを実行する場合:最初に、方向の変更を無効にする保存された値を確認します。
コードの解決策:
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"PortraitLandscapeIndicator"];
}
else {
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"PortraitLandscapeIndicator"];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//the latest saved orientation is our orientation
if([[NSUserDefaults standardUserDefaults] integerForKey:@"PortraitLandscapeIndicator"] == 1){
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
else{
return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
}