我使用按钮在XIB之间切换。我的功能是这样的:
-(IBAction)swapViews; {
SecondViewController *second2 =[[SecondViewController alloc
initWithNibName:@"SecondViewController" bundle:nil];
second2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:second2 animated:YES];
[second2 release];
}
如何在XIB之间使用滑动?
答案 0 :(得分:3)
为了能够在两个视图之间滑动,您不应该以模态方式显示它们(presentModalViewController
)。
查看[UIScrollView][1]
以及此simple tutorial。
简而言之,您应该创建UIScrollView
,它将为您管理滑动,然后通过滑动将您要管理的所有视图添加到UIScrollView
作为子视图。
- (void)loadView {
[super loadView];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
FirstViewController *first =[[FirstViewController alloc initWithNibName:@"FirstViewController" bundle:nil];
[scroll addSubview:first.view];
SecondViewController *second =[[SecondViewController alloc initWithNibName:@"SecondViewController" bundle:nil];
[scroll addSubview:second.view];
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];
[scroll release];
}