Showing posts with label Animations. Show all posts
Showing posts with label Animations. Show all posts

Monday, 22 June 2015

Animate a Table View as Dropdown in iOS

m File:
-(void)viewDidLoad
{
CGRect rect = CGRectMake(lbl_txt.frame.origin.x, lbl_txt.frame.origin.y+40, lbl_txt.frame.size.width, 0);
    [tbl_Cities setFrame:rect];
}


-(IBAction)clicked_cities:(id)sender
{
CGRect rect = CGRectMake(lbl_Selected_City.frame.origin.x, lbl_Selected_City.frame.origin.y+40, lbl_Selected_City.frame.size.width, 250);
    [UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[tbl_Cities setFrame:rect];
[UIView commitAnimations];

}

Animate a frames, After Load a Function in iOS

.m File:
-(IBAction)clicked_Language:(id)sender
{
    [UIView animateWithDuration:1.2f delay:0.0f options:UIViewAnimationOptionTransitionFlipFromRight animations:^
     {
         logo.frame = CGRectMake(180, 80, 215, 170);
         btn.frame = CGRectMake(180, 259, 228, 55);
         
     } completion:^(BOOL isDone)
     {
         if (isDone)
         {
             [self load_languages];
         }
     }];
}

-(void)load_languages
{
    //view_logo.frame = CGRectMake(53, 80, 215, 170);
    
    btn.alpha = 1;
    [UIView beginAnimations:@"animateTableView" context:nil];
    [UIView setAnimationDuration:0.5];
    btn.alpha = 0;
    [UIView commitAnimations];
    btn.hidden = YES;
    
    view_table.hidden = NO;
    view_table.alpha = 0;
    view_table.frame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y+5, 300, 300);
    [UIView beginAnimations:@"animateTableView" context:nil];
    [UIView setAnimationDuration:1.2];
    view_table.alpha = 1;
    [UIView commitAnimations];
    
    [table_language reloadData];
}

Friday, 22 August 2014

Marquee Label & AttributedString - Sample code

Download or copy the Two Files. Added code into your project.

MarqueeLabel.h

MarqueeLabel.m

Download Sample Code 

.m File
#import "MarqueeLabel.h"

@interface ViewController ()
{
    MarqueeLabel  *marquee_lbl;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

marquee_lbl = [[MarqueeLabel alloc]init];

NSString *newStr = @“Good for Health”;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:newStr];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@“Helvetica” size:11.0f] range:NSMakeRange(0, 3)];
    [attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:14.0f] range:NSMakeRange(4, newStr.length-4)];
    marquee_lbl.attributedText = attributedString;

if ([marquee_lbl.text length] > 30)
            {
                marquee_lbl.marqueeType = MLContinuous;
                marquee_lbl.scrollDuration = 10.0;
                marquee_lbl.animationCurve = UIViewAnimationOptionCurveEaseInOut;
                marquee_lbl.fadeLength = 5.0f;
                marquee_lbl.continuousMarqueeExtraBuffer = 200.0f;
                marquee_lbl.tag = 102;
            }

}

Saturday, 20 April 2013

Define and Move the Objects in Xcode

Step 1: Create a Project.

Step 2: Add the images into your project.

Step 3: In .h File Add the Codings are,

#import <UIKit/UIKit.h>

@interface Touchviewcontroller : UIViewController
{
    
}

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer;

@end

Step 4: In .m File Add the Codings are,

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer
{
    CGPoint translation = [recognizer translationInView:self.view];
    recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
                                         recognizer.view.center.y + translation.y);
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}

Step 5: In Xib File (Design)

  * Create a Image View  and  assign the image.

  * PanGestureRecognizer drag&drop to Image View.
  
  * FileOwner --> Outlets --> Map the handlePan to PanGestureRecognizer.


 
















Step 7: Build and Run the application. You can Select and move objects.


Move the Objects in XCode (Programatically)

Step 1: Create a Project.

Step 2: Add the images into your project.

Step 3: In .h File Add the Codings are,

#import <UIKit/UIKit.h>

@interface Touchviewcontroller : UIViewController
{
    
}

-(IBAction)create_obj:(id)sender;

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer;

@end

Step 4: In .m File Add the Codings are,

-(IBAction)create_obj:(id)sender
{
    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow.png"]];
    img.frame=CGRectMake(arc4random()%298, arc4random()%448, 60, 60);
    [img setUserInteractionEnabled:YES];

    [self.view addSubview:img];
 
    //For ScrollView
    //[ScrollView addSubview:img];
    
    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [img setUserInteractionEnabled:YES];
    [img addGestureRecognizer:panRecognizer];
    
}

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer
{
    CGPoint translation = [recognizer translationInView:self.view];
    recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
                                         recognizer.view.center.y + translation.y);
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}

Step 5: In Xib File(Design)



Step 6: Map the Create_obj to CreateObjects BarButton

Step 7: Build and Run the application.

                                                                        After Clicking Create Objects Button 

                                         




Friday, 15 February 2013

Animate Label or Image in Xcode

.h File

#import <UIKit/UIKit.h>

@interface Animation : UIViewController
{
    IBOutlet UILabel *labltext;
}

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

@end


.m File

-(void)viewDidLoad
{
    labltext.frame=CGRectMake(45, 20, 97, 21);
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:6.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    labltext.frame=CGRectMake(181, 321, 97, 21);
    [UIView commitAnimations];
}


Spin A label

-(void)viewDidLoad
{
    labltext.frame=CGRectMake(45, 20, 97, 21);
    [UIView beginAnimations:@"First" context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:6.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    labltext.frame=CGRectMake(181, 321, 97, 21);
    [UIView commitAnimations];
}


- (void)animationDidStop:(NSString *)animID finished:(BOOL)didFinish context:(void *)context
{
    if ([animID isEqualToString:@"First"])
    {
        [UIView beginAnimations:@"Last" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(10, 375, 100, 30);
        [UIView commitAnimations];
        
    }
    else if ([animID isEqualToString:@"Last"])
    {
        [UIView beginAnimations:@"Last1" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(220, 20, 100, 30);
        [UIView commitAnimations];
        
    }
    
    else if ([animID isEqualToString:@"Last1"])
    {
        [UIView beginAnimations:@"First1" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(10, 10, 100, 30);
        [UIView commitAnimations];
        
    }
    else if ([animID isEqualToString:@"First1"])
    {
        [UIView beginAnimations:@"First" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(220, 200, 100, 30);
        [UIView commitAnimations];
        
    }

}

Tuesday, 12 February 2013

Implementing Touch and Moved the Objects in Xcode

TouchingFunctionality.h File

#import <UIKit/UIKit.h>

@interface TouchingFunctionality : UIViewController
{
    IBOutlet UIImageView *image1;
    IBOutlet UIImageView *image2;
    IBOutlet UIImageView *image3;
    IBOutlet UIImageView *image4;
    IBOutlet UIImageView *image5;
    IBOutlet UIImageView *image6;
    IBOutlet UIImageView *image7;
    IBOutlet UIImageView *image8;
}

@end


TouchingFunctionality.m File


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title=@"Touch Function";
    
    
    UIBarButtonItem *btnSave=[[UIBarButtonItem alloc]initWithTitle:@"Save" style:UIBarButtonItemStyleBordered target:self action:@selector(save_Clicked)];
    self.navigationItem.rightBarButtonItem = btnSave;
    [btnSave release];
   
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    // get touch event
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
  if ([touch view] == image1) 
  {        
     image1.center = touchLocation;
  }
  else if ([touch view] == image2) 
  {        
     image2.center = touchLocation;
  }
  else if ([touch view] == image3) 
  {
     image3.center = touchLocation;
  }
  else if ([touch view] == image4) 
  {
     image4.center = touchLocation;
  }
  else if ([touch view] == image5) 
  {        
     image5.center = touchLocation;
  }
  else if ([touch view] == image6) 
  {       
     image6.center = touchLocation;
  }
  else if ([touch view] == image7) 
  {
     image7.center = touchLocation;
  }
  else if ([touch view] == image8) 
  {
     image8.center = touchLocation;
  }
}

//Saved a View as Image

-(void)save_Clicked
{
    UIGraphicsBeginImageContext(self.view.frame.size);
    [[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
}





Output:


View --> Attributes Inspector --> Change the propery of Interaction

                                                        * Enable the tick for Multiple Touch and User Interaction Enabled.




     * Map the images and Run the Application