2014-09-03 78 views
0

顯示幫助視圖我已經把UIImageView放在後面有一些UIButtons。我如何禁用這些按鈕的用戶交互?如果我觸摸此圖像的按鈕位於後面,它們會響應觸摸事件。禁用背景圖像背後的視圖交互

CODE FOR IMAGE背景:

self.helpBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; 
self.helpBackground.backgroundColor = [UIColor colorWithWhite:0 alpha:0.75]; 
self.helpBackground.hidden = YES; 
[self.view addSubview:self.helpBackground]; 

我使用self.helpBackground.userInteractionEnabled = NO;但沒有工作。

謝謝。

+0

你需要禁用用戶交互的所有按鈕不helpBackground ImageView的..! – Vidhyanand 2014-09-03 13:34:50

+0

當helpBackground打開時,您可以將所有按鈕設置爲button.hidden = YES。 – 2014-09-03 13:37:28

回答

0

把你的按鈕的陣列和循環通過他們,並禁用它們:

NSArray *buttonsArray = @[yourButton1, yourButton2]; 

for (UIButton *button in buttonsArray) { 
button.enabled = NO; 
} 

當你希望他們再次啓用只是環和設置enabledYES

0

保持標籤,就可以helpView( ImageView的),並添加以下代碼

for (UIView *view in self.view.subviews) { 
     if (view.tag != yourViewTag) { 
      view.userInteractionEnabled = NO; 
     } 
    } 

和刪除幫助屏幕後,使用下面的代碼

for (UIView *view in self.view.subviews) { 
      view.userInteractionEnabled = YES; 
    } 
0

你可以試試下面solution..When幫助imageview的是出現

for (UIView *view in [self.view subviews]) 
    { 
     if (view isKindOfClass:[UIButton Class]) 
     { 
      view.userInteractionEnabled = NO; 
     } 
     else 
     { 
      view.userInteractionEnabled = YES; 
     } 
    } 

////After dismissing the help screen you can 

    for (UIView *view in [self.view subviews]) 
    { 
     if (view isKindOfClass:[UIButton Class]) 
     { 
      view.userInteractionEnabled = YES; 
     } 
    } 

////(OR)簡單地做如下

self.view.userInteractionEnabled=YES; 

希望它可以幫助你..

0

您可以創建禁用用戶交互的方法,幫助您處理幫助下的所有視圖背景:

- (void)disableUserInteractionForViewsUnderView:(UIView *)view 
{ 
    CGRect area = view.frame; 
    for (UIView *underView in [self.view subviews]) { 
     if(CGRectContainsRect(area, underView.frame)) 
      underView.userInteractionEnabled = NO; 
    } 
} 

之後,你把它在你需要它:

[self disableUserInteractionForViewsUnderView:self.helpBackground]; 

編輯

我已經創建了一個github.com類UIViewController要點。你可以在這裏找到它:https://gist.github.com/alexcristea/0244b50e503e8bf4f25d

您可以使用它像這樣:

[self enumerateViewsPlacedUnderView:self.helpBackground usingBlock:^(UIView *view) { 
    if ([view isKindOfClass:[UIButton class]]) { 
     view.userInteractionEnabled = NO; 
    } 
}];