Tuesday, 28 August 2012

For remove UIDevice orientation warning just put bellow code in your file where you want to put fix orientation

For example if you want to your project only support Landscape or Portrait Orientation then when you put bellow line... i.e

    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

then its give warning like...
'UIDevice' may not respond to 'setOrientation:'

so for solve this warning just put bellow code where you use this line

@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)
- (void) setOrientation:(UIInterfaceOrientation)orientation;

Monday, 27 August 2012

Get Address From Latitude,Longitude....

Hi Friends,
Very simple method for get address from latitude and longitude method is bellow..

-(NSString *)getAddressFromLatLon:(double)pdblLatitude withLongitude:(double)pdblLongitude
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%f,%f&output=csv",pdblLatitude, pdblLongitude];
    NSError* error;
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
    locationString = [locationString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    return [locationString substringFromIndex:6];

and for get output just call this method like bellow..

NSString *strAddress = [self getAddressFromLatLon:yourLatitude withLongitude:yourLongitude];

NSLog(@"Address is %@",strAddress);

Friday, 24 August 2012

Rotate,Scale(ZoomIn,Zoomout) Multiple Image with GestureRecognizer...Very Easy..

        If we want to add Images Dynamically or custom more then time on the view ny the user and after that if we want to modify that image or recognize by Rotation or zoomin,zoomout then bellow code is very important and easy to use...

here, first you define the delegate and 2 variable in yourViewController.h file like bellow

@interface ViewController : UIViewController<UIGestureRecognizerDelegate>{

          CGFloat lastScale;
          CGFloat lastRotation;

after that in yourViewController.m file

        UIImageView *img = [[UIImageView alloc]init];
        [arrTag addObject:img];
        [arrTag retain];
        img.tag = [arrTag count];
        img.image = [UIImage imageNamed:[yourArray objectAtIndex:index]];//here use your array of object or array of imagename
        img.userInteractionEnabled = YES;
        img.frame = CGRectMake(yourViewController.view.center.x,yourViewController.view.center.y, 200, 200);
        UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
        [pinchRecognizer setDelegate:self];
        [img addGestureRecognizer:pinchRecognizer];
        [pinchRecognizer release];
        UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
        [rotationRecognizer setDelegate:self];
        [img addGestureRecognizer:rotationRecognizer];
        [rotationRecognizer release];

        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
        [tapRecognizer setNumberOfTapsRequired:1];
        [tapRecognizer setDelegate:self];
        [img addGestureRecognizer:tapRecognizer];
        [tapRecognizer release];
        [yourViewController.view addSubview:img];
        [yourViewController.view bringSubviewToFront:img];
        [img release];

After that define bellow Methods..

#pragma mark GestureRecognizer Methods

-(void)scale:(id)sender {
     UIView *imgTempGest = [sender view];
     if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
             lastScale = 1.0;
     CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]);
     CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
     CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
     [[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];
    [imgTempGest setTransform:newTransform];
     lastScale = [(UIPinchGestureRecognizer*)sender scale];

-(void)rotate:(id)sender {
    UIView *imgTempGest = [sender view];
     if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
             lastRotation = 0.0;
      CGFloat rotation = 0.0 - (lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);
      CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
      CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);
      [[(UIRotationGestureRecognizer*)sender view] setTransform:newTransform];
      [imgTempGest setTransform:newTransform];
      lastRotation = [(UIRotationGestureRecognizer*)sender rotation];

-(void)tapped:(id)sender {
      UIView *imgTempGest = [sender view];
      [[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations];
      [[imgTempGest layer] removeAllAnimations];

Thursday, 23 August 2012

Move Object on view with Filtered Class Like.. UIImageView class and its tag,etc.

Here you can easily move image object with particular tag or only for imageview class.

if you want to some selected images are only  move then just give here image.tag = something and then bellow method in put condition like 

if(tempImage.tag == yourTag)
     tempImage.center = pointToMove; 

you can easily handle your all object..

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
       UITouch *tap = [touches anyObject];

       CGPoint pointToMove = [tap locationInView:viewBoard];
       if([touch.view isKindOfClass:[UIImageView class]])

             UIImageView *tempImage=(UIImageView *) tap.view;
             [UIView beginAnimations:nil context:NULL];
             [UIView setAnimationDuration:0.0f];
             [UIView setAnimationBeginsFromCurrentState:YES];
             [UIView setAnimationCurve:UIViewAnimationCurveLinear];
             tempImage.center = pointToMove; 
             [UIView commitAnimations];