ランドスケープでのみ操作したいアプリがあります。
初めて IB に先んじて、すべてのビューをプログラムでセットアップしようとしているので、ビューを作成し、loadView メソッドに一連のサブビューを追加しています。
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.mapView.myLocationEnabled = YES;
self.mapView.delegate = self;
self.mapView.mapType = kGMSTypeHybrid;
self.mapView.frame = self.view.frame;
[self.view addSubview:self.mapView];
// add the toolbar
UIToolbar* toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, self.view.frame.size.height - 44, self.view.frame.size.width, 44);
toolbar.barStyle = UIBarStyleDefault;
NSMutableArray* items = [NSMutableArray array];
[items addObject:[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"location-arrow.png"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(locateMe:)]];
[items addObject:[[UIBarButtonItem alloc] initWithTitle:@"Tools"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(toolsButtonTapped:)]];
[toolbar setItems:items];
[self.view addSubview:toolbar];
私のプロジェクト設定では、両方の縦向きを無効にしました。ルートビューコントローラーにもこれがあります:
// Enforce Landscape Orientation
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
私の問題は、シミュレーターが横向きモードで起動することですが、すべてのビューが縦向きのサイズになっているため、ビューの下部のチャンクが画面の下にあり、画面の右側が大きな空の領域です。
最初の行でアプリケーション フレームの幅と高さを切り替えることでこれを修正しようとしましたが、ステータス バーの画面の左端に空の垂直方向の部屋が残ります。
それで、私がやろうとしていることをする正しい方法は何ですか?