Code:
Header file:
@interface game : UIViewController
{
UIImageView *anh[8][8];
}
-(void)SwipeToMove:(id)sender;
@end
Implementation file:
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *move = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeToMove:)];
[move setDirection:(UISwipeGestureRecognizerDirectionUp)];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
anh[i][j]=[[UIImageView alloc] initWithFrame:CGRectMake(0+40*i,200 + 40*j,40,40)];
anh[i][j].userInteractionEnabled = YES;
[self.view addSubview:anh[i][j]];
anh[i][j].image = [UIImage imageNamed:@"Earth.png"];
[anh[i][j] addGestureRecognizer:move];
}
}
}
-(void)SwipeToMove:(id)sender{
NSLog(@"ok");
}
The UIImageView
works as expected, but UISwipeGestureRecognizer
is not working. Then, I tried this:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(100,50,40,40)];
label1.image = [UIImage imageNamed:@"Ceres.png"];
[self.view addSubview:image1];
image1.userInteractionEnabled = YES;
image1.image = [UIImage imageNamed:@"Earth.png"];
UISwipeGestureRecognizer *move = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(SwipeToMove:)];
[move setDirection:(UISwipeGestureRecognizerDirectionUp)];
[image1 addGestureRecognizer:move];
-(void)SwipeToMove:(id)sender{
NSLog(@"OK");
}
It's working, but I need an array of UIImageView
s to make my app. Please help me.