Monday, July 30, 2012

thumbnail

UP DOWN Animation with Different Speed Objective C

This Animation is look like Bio Breathing Animation, Upward and Downward with different speed.


.h file


//
//  Created by Nasrullah Mahar on 7/18/12.
//

#import

@interface BioBreathAnimationView  : UIViewController
{
    IBOutlet UIView *upView;
    IBOutlet UIView *downView;
    IBOutlet UIView *mainView;
    
    BOOL isAnimated;
    IBOutlet UILabel *inhaleLabel;
    IBOutlet UILabel *exhaleLabel;
    
    IBOutlet UISlider *inhaleSlider;
    IBOutlet UISlider *exhaleSlider;
    
    IBOutlet NSTimer *CallingTimer;
    
}


@property(nonatomic,retain) IBOutlet  UIView *upView;
@property(nonatomic,retain) IBOutlet  UIView *downView;
@property(nonatomic,retain) IBOutlet  UIView *mainView;

@property(nonatomic,retain) IBOutlet  NSTimer *CallingTimer;

@property(nonatomic,retain) IBOutlet  UISlider *inhaleSlider;
@property(nonatomic,retain) IBOutlet  UISlider *exhaleSlider;

@property (nonatomic, retain) IBOutlet UILabel *inhaleLabel;
-(IBAction)sliderInhaleChanged:(id)sender;

@property (nonatomic, retain) IBOutlet UILabel *exhaleLabel;

-(IBAction)sliderExhaleChanged:(id)sender;


@end


.m file




//  Created by Nasrullah Mahar on 7/18/12.


#import "BioBreathAnimationView.h"

@interface BioBreathAnimationView ()

@end

@implementation BioBreathAnimationView 

@synthesize inhaleLabel,exhaleLabel,inhaleSlider,exhaleSlider,upView,downView,mainView,CallingTimer;

float inhaleval=3.5,exhaleval=4.5;
float duration = 3.5;



-(IBAction)sliderInhaleChanged:(id)sender
{
    UISlider *slider = (UISlider *)sender;
    inhaleval = (float)(slider.value + 0.5f);
    int progressAsInt = (int)(slider.value + 0.5f);
    NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt];
    inhaleLabel.text=newText;
    [newText release];
    
    duration = inhaleval;
    
    if (CallingTimer != nil) {
            [CallingTimer invalidate];
    }

    
  CallingTimer =  [[NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(ShowHide) userInfo:nil repeats:NO]retain];

   
}

-(IBAction)sliderExhaleChanged:(id)sender
{
    UISlider *slider = (UISlider *)sender;
    exhaleval = (float)(slider.value + 0.5f);
    int progressAsInt = (int)(slider.value + 0.5f);
    NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt];
    exhaleLabel.text=newText;
    [newText release];
    
    duration = inhaleval;
    
    if (CallingTimer != nil) {
        [CallingTimer invalidate];
    }
    
   CallingTimer = [[NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(ShowHide) userInfo:nil repeats:NO]retain];

    
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}




- (void)viewDidLoad
{
    //Load Automatically
    
    
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    isAnimated = NO;
    
    [NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(ShowHide) userInfo:nil repeats:NO];

}




-(void)ShowHide
{
    switch (isAnimated) {
        case YES: //it's show tableview
            
            self.upView.hidden   = NO;   // Blue
            self.downView.hidden = YES;
            [upView setFrame:CGRectMake(0.0, 0.0, 111.0, 218.0)];
            
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationCurve:UIViewAnimationCurveLinear];
            [UIView setAnimationDuration:exhaleval];
            [upView setFrame:CGRectMake(0.0, 213.0, 111.0, 5.0)];
            [UIView commitAnimations];
            isAnimated = NO;
            duration = exhaleval;
            
            //duration = inhaleval;
            
            if (CallingTimer != nil) {
                [CallingTimer invalidate];
            }
            
            CallingTimer = [[NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(ShowHide) userInfo:nil repeats:NO]retain];
            
            break;
            
        case NO: //it's show mapview
            
            self.upView.hidden   = YES;
            self.downView.hidden = NO;
            [downView setFrame:CGRectMake(0.0, 213.0, 111.0, 5.0)];
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationCurve:UIViewAnimationCurveLinear];
            [UIView setAnimationDuration:inhaleval];
            // [UIView setAnimationRepeatCount: 10000];
            // [UIView setAnimationRepeatAutoreverses: YES];
            [downView setFrame:CGRectMake(0.0, 0.0, 111.0, 218.0)];
            [UIView commitAnimations];
            isAnimated = YES;
            
            duration = inhaleval;
            
            //duration = inhaleval;
            
            if (CallingTimer != nil) {
                [CallingTimer invalidate];
            }
            
            CallingTimer = [[NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(ShowHide) userInfo:nil repeats:NO]retain];
            
            break;
            
        default:
            break;
            
           
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}



@end

xib file




Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

comments

About me

simple one.