Search This Blog

Feb 1, 2011

How to Flip a UIView ?

This examples shows how to Flip a UIView with animation effect. For flip a UIView I am using delegate method. We create two Controller FirstViewController and SecondViewController.

You can download source code from here Download.

Code for FirstViewController.h file.

#import
#import "SecondViewController.h"

@interface FirstViewController : UIViewController {

}

- (IBAction)btnSecondView_Clicked:(id)sender;

@end


Code for FirstViewController.m file.

#import "FirstViewController.h"
#import "SecondViewController.h"

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)btnSecondView_Clicked:(id)sender{

    [UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
    SecondViewController *secondView = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
    secondView.delegate = self;
    secondView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:secondView animated:YES];
    [secondView release];
    [UIApplication sharedApplication].networkActivityIndicatorVisible =FALSE;
}

-(void)flipsideViewControllerDidFinish:(SecondViewController *)secondView{
  
    [self dismissModalViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
  
    [super didReceiveMemoryWarning];
  
}


- (void)dealloc {
    [super dealloc];
}


@end

Code for SecondViewController.h file.

#import

@protocol FlipsideViewControllerDelegate;

@interface SecondViewController : UIViewController {

    id delegate;
}

@property(nonatomic, assign)id delegate;

-(IBAction)btnBack_Clicked:(id)sender;

@end


@protocol FlipsideViewControllerDelegate

-(void)flipsideViewControllerDidFinish:(SecondViewController *)secondView;

@end


Code for SecondViewController.m file.

#import "SecondViewController.h"


@implementation SecondViewController
@synthesize delegate;

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(IBAction)btnBack_Clicked:(id)sender{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [self.delegate flipsideViewControllerDidFinish:self];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void)didReceiveMemoryWarning {
   
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}


@end

No comments:

Post a Comment