Rahul Vyas
Rahul Vyas

Reputation: 28720

Flip views in iPhone?

I have a UIView which has a button, On the button's tap I am showing a new UIView which contain a UINavigationBar and a UITableView. Is there any way to animate a flip effect on button's tap and load the view and also vice versa ?

Upvotes: 1

Views: 2801

Answers (1)

Heat Miser
Heat Miser

Reputation: 19758

Sure, here is some code that may help

- (void)flipAction:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];
    // checks to see if the view is attached
    [UIView setAnimationTransition:([logTextView superview] ?
                                    UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
                           forView:[self view] cache:YES];
    [UIView setAnimationTransition:([logTextView superview] ?
                                    UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
                           forView:[[self navigationController] view] cache:YES];
    if ([logTextView superview])
    {
        [logTextView removeFromSuperview];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"FTP Log", nil) style:UIBarButtonItemStyleBordered target:self action:@selector(viewFtpLog)];
    }
    else
    {
        [[self view] addSubview:logTextView];
        [[[self navigationItem] rightBarButtonItem] release];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) style:UIBarButtonItemStyleDone target:self action:@selector(flipAction:)];
    }

    [UIView commitAnimations];
}

For you, you might want to get the UIView for your table view. The button is what triggers the flip

Upvotes: 1

Related Questions