0

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 の使用

4

1 に答える 1

0
Do like this
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait ){
      FACING = @"PU";
  }
  if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown ){
      FACING = @"PD";
  }
  if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
      FACING = @"LL";
  }
  if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight ){
      FACING = @"LR";
  } 

したがって、それぞれのブロックで必要なフレームを設定します。機能します。

于 2013-08-07T09:16:38.177 に答える