0

I wrote a basic two-view application that switches from one view to another every time I press a button.

But for some reason when I run it on simulator, both views are always few pixels above the MainWindow.xib view, always being on top of it. And what's strange is that there is no animation when I switch between Views.

What is the problem???

This is what I have in my 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];
}
NoobDev4iPhone
  • 5,531
  • 10
  • 33
  • 33

3 Answers3

0

Hi Try This,

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

Also try this

[UIView transitionWithView:view2 duration:0.5
        options:UIViewAnimationTransitionFlipFromLeft //change to whatever animation you like
        animations:^ { [window addSubview:view2]; }
        completion:nil];
Krrish
  • 2,256
  • 18
  • 21
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;

    }

}
Hariprasad.J
  • 307
  • 1
  • 12