横向きモードに制限する必要がある iPad アプリを開発しています。ルート ビュー コントローラーとサブビュー コントローラーがあります。サブ ビュー コントローラーをルート ビュー コントローラーに追加し、フレームを 1024x768 に設定します。info.plist とビュー コントローラーの
shouldAutorotateToInterfaceOrientation:interfaceOrientation
メソッドで、アプリをランドスケープ モードに制限しました。viewDidAppear
ただし、サブビューのサイズは、ポートレート モードであるかのように表示するメソッドの前に、768x1024 にリセットされます。
奇妙な部分は、幅または高さが画面の寸法以外になるようにサブビューのフレームを設定した場合です。たとえば、 CGRectMake(0, 0, 1024, 767) または CGRectMake(0, 0, 1024, 769 ) 、リセットされず、横向きモードのように表示されます。
私の質問は、この動作の原因は何ですか。そして、すべてのビューを横向きモードにデフォルト設定するための最良の方法は何ですか?
これが私のルートView Controllerです:
// INTERFACE
#import <UIKit/UIKit.h>
#import "ScrapViewController.h"
@interface ViewController : UIViewController
{
ScrapViewController *svc;
}
@end
// IMPLEMENTATION
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
self.view.frame = CGRectMake(0, 0, 1024, 768);
svc = [[SubViewController alloc] init];
svc.view.backgroundColor = [UIColor redColor];
svc.view.frame = CGRectMake(0, 0, 1024, 768);
[self.view addSubview:svc.view];
NSLog(@"viewDidLoad rvc %f,%f", self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"viewDidLoad svc %f,%f", svc.view.frame.size.width, svc.view.frame.size.height);
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
@end
これが私のサブビューコントローラーです
// INTERFACE
#import <UIKit/UIKit.h>
@interface SubViewController : UIViewController
@end
// IMPLEMENTATION
@implementation SubViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
@end