iPhoneアプリ開発初心者です。ナビゲーション バー内でカスタマイズされた uisegmentedcontrol を使用しています。
このコードは iPhone でうまく機能します。
[self.navigationItem setHidesBackButton:YES animated:YES];
profileSegmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects: @"seg1", @"seg2", @"seg3", @"seg4", nil]];
[profileSegmentControl addTarget:self action:@selector(seg1Button) forControlEvents:UIControlEventValueChanged];
**profileSegmentControl.frame = CGRectMake(40, 25, 310, 30);**
profileSegmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
profileSegmentControl.momentary = YES;
//[profileSegmentControl sizeToFit];
UIBarButtonItem *profileSegmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:profileSegmentControl];
self.navigationItem.rightBarButtonItem = profileSegmentBarItem;
さて、向きを縦から横に変更すると、CGRectMake で uisegmentedcontroll ボタンの座標を変更する方法を教えてください。横向きの場合、幅は 310 ではなく 510 にする必要があります。
ナビゲーション バーの「戻る」ナビゲーション ボタンを非表示にしているため、[segmentControlObject sizeToFit] を使用できません。これを試してみましたが、segmentedControl の幅がナビゲーション バー全体をカバーしていません。
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation メソッドを認識していますが、これを viewDidLoad または任意のメソッドで呼び出すことはできません。
xcode 4.6 の使用