Tuesday 2 April 2013

(38)How to drag image or button in iPhone SDK using UITouch Events ?


This code is show UITouch delegate methods. In this example we use touchMoved delegate method for dragging the image. 



1. Code for .h file.

#import
 


@interface UIDrawController : UIViewController {

    IBOutlet UIImageView *imgApple;
}

@end

2. Code for .m file.

#import "UIDrawController.h"


@implementation UIDrawController

- (void)viewDidLoad {
    [super viewDidLoad];
  
 
    self.navigationController.navigationBar.hidden = TRUE;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint pointMoved = [touch locationInView:self.view];  
 
    imgApple.frame = CGRectMake(pointMoved.x, pointMoved.y, 64, 64);
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
  
 
    // Release any cached data, images, etc that aren't in use.
}

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


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


@end

No comments:

Post a Comment