2011-08-09 42 views
0

我使用按鈕在XIB之間切換。我的功能是這樣的:在XIB之間滑動

-(IBAction)swapViews; { 
    SecondViewController *second2 =[[SecondViewController alloc 
     initWithNibName:@"SecondViewController" bundle:nil]; 
    second2.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:second2 animated:YES]; 
    [second2 release]; 
} 

如何在XIB之間使用滑動?

回答

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]; 

}

+0

但我在同一個XIB –

+0

沒有問題,許多廈門國際銀行並不多視圖。看看我的編輯...我加載兩個xib並將它們放在滾動視圖中...對你有意義嗎? – sergio

+0

是thx brooooo –