I've been having problems trying to get an imageview to move when being dragged in my view, *gameView. I got it to work in my view only when i declared my imageview as an IBOutlet and connecting it in Interface Buider, but that's not the case in my situation. here's my code, if anyone can help it's very much appreciated.
.h file
m. file
So for this code nothing happens when I drag the image. i also tryed using
nadda : /
.h file
Code:
@interface ViewController : UIViewController <UIActionSheetDelegate> {
UIImageView *imageView;
UIView *gameView
UIImage *randomImage;
NSMutableArray *array;
}
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIImage *randomImage;
@property (nonatomic, retain) IBOutlet UIView *gameView;
@property (nonatomic, retain) NSMutableArray *array;
m. file
Code:
@implementation ViewController
@synthesize imageView;
@synthesize gameView;
@synthesize randomImage;
@synthesize array;
- (void)viewDidLoad {
randomImage = [array objectAtIndex: arc4random() % [array count]];
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(164, 162, 46, 72)];
imageView.image = randomImage;
[self.view addSubview:imageView];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == imageView) {
CGPoint location = [touch locationInView:gameView];
imageView.center = location;
}
}
So for this code nothing happens when I drag the image. i also tryed using
Code:
UITouch *touch = [[event allTouches] anyObject];
nadda : /
Last edited: