0

次のシナリオがあります。

UITabBarController
--tab1
--tab2
----UINavigationController (with a UITableViewController and 3 rows)
------pushedViewController
--tab3
--tab4
--tab5

ユーザーが UINavigationViewController のオプションをクリックすると、「pushedViewController」がプッシュされます。そのビューコントローラーでは、App Store http://i.stack.imgur.com/hrdxLにあるようなセグメント化されたコントロールが必要です。 .png

これどうやってするの?

私はすでにチェックしました

https://stackoverflow.com/questions/1559794/changing-views-from-uisegmentedcontrol
https://stackoverflow.com/questions/5280653/uisegmentedcontrol-to-switch-views-in-uitabbarcontroller
http://www.astroryan.com/?p=19
https://stackoverflow.com/questions/8723094/using-uisegmentedcontrol-to-switch-between-two-views

これは私を助けることができますが 、UISegmentedControlを使用してUIViewControllerを切り替える方法がわかりません

そして、このユーザーは同じことを尋ねましたが、完全なコードはありません iPhone App Store からセグメント化されたコントロールを再作成しています

4

1 に答える 1

0

pushViewControllerには、画面全体にフレーム化されたUIScrollViewを含めることができます。ページングを有効に設定し、次のように3つの大きなサブビューを設定します。

CGFloat width = self.view.bounds.width;
CGFloat height = self.view.bounds.height;

// it's easier to do all this this in xib/storyboard, but to illustrate...

self.scrollView.frame = CGRectMake(0,0,width,height);
self.scrollView.contentSize = CGSizeMake(width*3.0, height);  // this must be done in code
self.scrollView.pagingEnabled = YES;

UIView *subviewA, *subviewB, subviewC;

subviewA.frame = CGRectMake(0.0, 0.0, width, height);
subviewB.frame = CGRectMake(0.0, width, width, height);
subviewB.frame = CGRectMake(0.0, 2.0*width, width, height);

[self.scrollView addSubview:subviewA];
[self.scrollView addSubview:subviewB];
[self.scrollView addSubview:subviewC];

// then when the segmented control changes ...

- (IBAction)segmentedControlChanged:(UISegmentedControl *)sender {

    NSInteger page = sender.selectedSegmentIndex;
    CGFloat contentOffsetX = page*self.view.bounds.width;
    [self.scrollView setContentOffset:CGPointMake(contentOffsetX, 0.0) animated:YES];
}
于 2012-05-06T01:59:43.973 に答える