how to drage image in iphone using programming?

Leave a Comment
Here i am going to explain you how to drag image or UITouch events deep knowledge.In this tutorials you can see that when you press mouse than fish will come at that location.

devangViewController .h


#import <UIKit/UIKit.h>
@interface devangViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *fish1;

@end

devangViewController .m

#import "devangViewController.h"
@interface devangViewController ()
@end
@implementation devangViewController
@synthesize fish1;
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
fish1.center = location;

 
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
I think it's enough to understand this tutorials.

Output:





0 comments:

Post a Comment