2016-08-05 65 views
0

我有3个图像浏览,我想阻止同时点击图像浏览。我怎样才能做到这一点?谁能帮我??防止同时点击图像浏览

for (int i=0; i <= [_images1 count]-1; i++){ 
    CGFloat xOrigin = i * self.view.frame.size.width/3; 
    wordsImage = [[UIImageView alloc] init]; 

    [wordsImage setFrame:CGRectMake(xOrigin+20, self.view.frame.size.height/3,self.view.frame.size.width/3.5 , self.view.frame.size.height/5)]; 
    [wordsImage setImage:[UIImage imageNamed: [_images1 objectAtIndex:i]]]; 
    [self.view addSubview:wordsImage]; 
    [wordsImage setTag:i]; 
    wordsImage.userInteractionEnabled = YES; 

    tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:index_image:)]; 
    tapGesture1.numberOfTapsRequired = 1; 

    [tapGesture1 setDelegate:self]; 

    [wordsImage addGestureRecognizer:tapGesture1]; 
} 
+0

刚才设置的用户交互模式=没有供选择图像 –

+0

如何使用标签值 – Bharathi

+0

检查我的答案@Bharathi –

回答

0

如果要防止同时点击Imageviews,可以通过YES设置exclusiveTouch

/* exclusiveTouch 
    A Boolean value that indicates whether the receiver handles touch events exclusively. 
    Setting this property to YES causes the receiver to block the delivery of touch events to other views in the same window. The default value of this property is NO. 
*/ 
    for (int i=0; i <= [_images1 count]-1; i++){ 
     CGFloat xOrigin = i * self.view.frame.size.width/3; 
     wordsImage = [[UIImageView alloc] init]; 

     [wordsImage setFrame:CGRectMake(xOrigin+20, self.view.frame.size.height/3,self.view.frame.size.width/3.5 , self.view.frame.size.height/5)]; 
     [wordsImage setImage:[UIImage imageNamed: [_images1 objectAtIndex:i]]]; 
     [self.view addSubview:wordsImage]; 
     [wordsImage setTag:i]; 
     wordsImage.userInteractionEnabled = YES; 
     wordsImage.exclusiveTouch = YES;//Set this property 

     tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:index_image:)]; 
     tapGesture1.numberOfTapsRequired = 1; 

     [tapGesture1 setDelegate:self]; 

     [wordsImage addGestureRecognizer:tapGesture1]; 
    } 

我希望这将是有益的

+0

谢谢设置..它帮助 – Bharathi

+0

@Bharathi欢迎您。 – HDT

0

W¯¯母鸡你点击图像视图设置一个Bool变量true和管理变量。

1

使用此方法来限制单击相同的ImageView的序列。我希望这能帮到您。

int previousTag,curentTag,flag; 
-(void)tapGesture:(id)sender{ 
    UIGestureRecognizer *recognizer = (UIGestureRecognizer*)sender; 
    UIImageView *imageView = (UIImageView *)recognizer.view; 

    if(flag == 0){ 
     previousTag = imageView.tag; 
     curentTag = 520; // unequal value you will enter here 
     flag = 1; 
    } 
    else { 
     curentTag = imageView.tag; 
    } 

    if(previousTag != curentTag) 
    { 
     [imageView setImage:[UIImage imageNamed:@"anyImage.png"]]; 
     previousTag = curentTag; 
    } 

} 
相关问题