Sample of Keyframe Animations in ios

CALayer *layer = [CALayer layer];

[layer setPosition:CGPointMake(100.0, 100.0)];

[layer setBounds:CGRectMake(0.0, 0.0, 50.0, 60.0)];

[layer setBackgroundColor:[[UIColor redColor] CGColor]];

[self.view.layer addSublayer:layer];


CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@”position”];


//NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.33], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];

//[anim setKeyTimes:times];


NSArray *values = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(100., 100.)], 

  [NSValue valueWithCGPoint:CGPointMake(100., 200.)],

  [NSValue valueWithCGPoint:CGPointMake(220., 200.)], 

  [NSValue valueWithCGPoint:CGPointMake(220., 100.)], nil];

[anim setValues:values];


[anim setDuration:6.0]; //seconds

[anim setCalculationMode:kCAAnimationCubic];

[layer addAnimation:anim forKey:@”position”];


Difference between Frame and Bounds in iphone programming

The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).

The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

So, imagine a view that has a size of 100×100 (width x height) positioned at 25,25 (x,y) of its superview. The following code prints out this view’s bounds and frame:

// This method is in the view controller of the superview
- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"bounds.origin.x: %f", label.bounds.origin.x);
    NSLog(@"bounds.origin.y: %f", label.bounds.origin.y);
    NSLog(@"bounds.size.width: %f", label.bounds.size.width);
    NSLog(@"bounds.size.height: %f", label.bounds.size.height);

    NSLog(@"frame.origin.x: %f", label.frame.origin.x);
    NSLog(@"frame.origin.y: %f", label.frame.origin.y);
    NSLog(@"frame.size.width: %f", label.frame.size.width);
    NSLog(@"frame.size.height: %f", label.frame.size.height);

And the output of this code is:

bounds.origin.x: 0
bounds.origin.y: 0
bounds.size.width: 100
bounds.size.height: 100

frame.origin.x: 25
frame.origin.y: 25
frame.size.width: 100
frame.size.height: 100

So, we can see that in both cases, the width and the height of the view is the same regardless of whether we are looking at the bounds or frame. What is different is the x,y positioning of the view. In the case of the bounds, the x and y coordinates are at 0,0 as these coordinates are relative to the view itself. However, the frame x and y coordinates are relative to the position of the view within the parent view (which earlier we said was at 25,25).



referred from stackOverflow

Encoding the special charecters of a NSString in Objective-c

NSString *unescaped = @"http://www";
NSString *escapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(

NSLog(@"escapedString: %@",escapedString);

NSLog output:

escapedString: http%3A%2F%2Fwww

Under ARC one alternative is:

NSString *escapedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
   (__bridge CFStringRef) unescaped,

Ad Mob code in ios

    bannerView = [[GADBannerView alloc]
                  initWithFrame:CGRectMake(0, 335, 320, 35)];


    AbMob = [[GADBannerView alloc]
                      self.view.frame.size.height – GAD_SIZE_300x250.height,GAD_SIZE_320x50.width,GAD_SIZE_320x50.height)];
    bannerView.adUnitID = @”your admob id”;
    bannerView.rootViewController = self;
    [self.view addSubview:bannerView];
    GADRequest *r = [[GADRequest alloc] init];

//keep testing =Yes if the ad is in testing phase and while uplaoding to appstore remove this line
    r.testing = YES;
    [bannerView loadRequest:r];

The frameworks need to be included for admobs are

  • StoreKit
  • AudioToolbox
  • MessageUI
  • SystemConfiguration
  • CoreGraphics
  • AdSupport

and do not forget if you are using the admob version> 6.1 add -ObjC to Otherlinker flags in build settings