2012-02-29 36 views
0

我寫了一個基本的雙視圖應用程序,每次按下按鈕時都從一個視圖切換到另一個視圖。初學者:多視圖應用程序不能正確切換視圖

但由於某些原因,當我在模擬器上運行它時,兩個視圖總是在MainWindow.xib視圖上方几個像素,始終位於其上。奇怪的是,當我在Views之間切換時沒有動畫。

是什麼問題?

這是我在我的AppDelegate.m

-(void)switchView:(UIView *)view1 toView:(UIView *)view2{ 

    [UIView beginAnimations:@"Animation" context:nil]; 
    [UIView setAnimationDuration:1.75]; 
    [UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromLeft forView:self.window cache:YES]; 
    [view1 removeFromSuperview]; 
    [window addSubview:view2]; 
    [UIView commitAnimations]; 
} 

回答

0

嗨試試這個,

-(void)switchView:(UIView *)view1 toView:(UIView *)view2 
    { 
     view2.frame = self.window.bounds; 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDuration:0.5f]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view2 cache:NO]; 
     [view1 removeFromSuperview]; 
     [window addSubview:view2]; 
     [UIView commitAnimations]; 
    } 

也可以嘗試這個

[UIView transitionWithView:view2 duration:0.5 
     options:UIViewAnimationTransitionFlipFromLeft //change to whatever animation you like 
     animations:^ { [window addSubview:view2]; } 
     completion:nil]; 
0
 Can you post some code regarding this .Because if you click on Segment change 
it will change the Views.IF you take two views on same interface Builder. 
     Try out this 

    IBOutlet UIView *viewA; 
    IBOutlet UIView *viewB; 

    in .m file 



-(IBAction)SegmentChange 
{ 
    if(segment.selectedSegmentIndex==0) 
    { 
     viewA.hidden=NO; 
     viewB.hidden=YES; 


    } 

    else if(segment.selectedSegmentIndex==1) 
    { 
     [self.View addSubview:viewB]; 
     viewA.hidden=YES; 
     viewB.hidden=NO; 

    } 

}