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 在 UIViewControllers 之间切换

这个用户也问了同样的问题,但它没有完整的代码 Recreating Segmented Control from iPhone App Store

4

1 回答 1

0

pushViewController 可以包含一个填充屏幕的 UIScrollView。启用分页,并给它三个大子视图,如下所示:

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 回答