我想在每个可以移动的图像上设置轻击手势,但是没有在每个图像上设置手势

时间:2014-09-06 07:04:17

标签: ios

我想在点击按钮添加时添加UIImageView,并且想要在每个可以移动的图像上设置点击手势,不知何故我添加了图像但是没有在每个图像上设置手势

添加图片

 -(IBAction)addImageAction:(id)sender{

if (flag == true) {
    imgNew = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];
    flag = false;
}else{
    imgNew = [[UIImageView alloc]initWithFrame:CGRectMake(imgNew.frame.origin.x+15, imgNew.frame.origin.y+15, 70, 70)];
}

[imgViewArray addObject:imgNew];
[viewMain addSubview:imgNew];
[imgNew setUserInteractionEnabled:YES];
[imgNew setImage:[UIImage imageNamed:@"Doraemon.png"]];
[self gestureMethod];
}

触摸方法

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [touches anyObject];

if ([touch view] == img1)
{
    NSLog(@"its 1st image");
    // set imageview to 1st image
     img = img1;
}else if ([touch view] == img2){
    NSLog(@"its second image");
     // set imageview to 2nd image
     img = img2;
}else {
    img = imgNew;
}
[self gestureMethod];
NSLog(@"%@",touch.view.description);

}

在gestureMethod我完成了移动图像和放大和缩小的代码

0 个答案:

没有答案