2012-08-31 11 views
25

मैं अक्षम करने कर रहा हूँ और निम्नलिखित कोड का उपयोग कर एक दृश्य को सक्षम करने में बातचीत ....अक्षम उपयोगकर्ता एक दृश्य आईओएस

[self.view setUserInteractionEnabled:NO]; 
[self.view setUserInteractionEnabled:YES]; 

मैं इस तरह करते हैं, यह सब subviews भी प्रभावित हो गया ... सभी अक्षम हैं , मैं केवल विशेष दृश्य के लिए कैसे करूं? क्या यह संभव है?

उत्तर

31

यह बिल्कुल वैसा ही, अपने अन्य दृश्य संभालने या तो एक सदस्य या आप self.view के subviews के सरणी के माध्यम से पुनरावृति सकता है, इसलिए की तरह है है:

MyViewController.h

UIView* otherView; 

MyViewController.m

otherView.userInteractionEnabled = NO; // or YES, as you desire. 

या:

for (int i = 0; i < [[self.view subviews] count]; i++) 
{ 
    UIView* view = [[self.view subviews] objectAtIndex: i]; 

    // now either check the tag property of view or however else you know 
    // it's the one you want, and then change the userInteractionEnabled property. 
} 
5
for (UIView* view in self.view.subviews) { 

    if ([view isKindOfClass:[/*"which ever class u want eg UITextField "*/ class]]) 

     [view setUserInteractionEnabled:NO]; 

} 

आशा है कि यह मदद करता है। खुश कोडन :)

1

सबसे अच्छा विकल्प नहीं बल्कि अपने सभी subviews पुनरावृत्ति से देखने का Tag संपत्ति का प्रयोग है। बस उपव्यू में टैग सेट करें जिसे आप इंटरैक्शन अक्षम करना चाहते हैं और इसे एक्सेस करने के लिए कोड का उपयोग करें और इंटरैक्शन अक्षम करें।

// considering 5000 is tag value set for subView 
// for which we want to disable user interaction 
UIView *subView = [self.view viewWithTag:5000]; 
[subView setUserInteractionEnabled:NO]; 
+0

धन्यवाद यह मेरे लिए काम किया, फिर भी मैं कई बार देखा गया तो मैं उन सब को छिपाने के लिए की जरूरत है। एक और चीज जो मैंने किया वह पृष्ठभूमि के साथ एक दृश्य था ताकि वह उस दृश्य को भूरे रंग से देख सके जिसे मैं अक्षम कर रहा था। – Gram

8

तेज UIView में यह संवेदनशील है या नहीं करने के लिए संपत्ति userInteractionEnabled है। पूर्ण देखें अनुत्तरदायी उपयोग कोड बनाने के लिए:

// make screen unresponsive 
self.view.userInteractionEnabled = false 
//make navigation bar unresponsive 
self.navigationController!.view.userInteractionEnabled = false 

// make screen responsive 
self.view.userInteractionEnabled = true 
//make navigation bar responsive 
self.navigationController!.view.userInteractionEnabled = true 
संबंधित मुद्दे