2016-08-05 101 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; 
    } 

} 
相關問題