2009-09-11 13 views
11

मेरे पास एक सबव्यूव है जो मेरे UIView में जोड़ा गया है। विचार यह है कि सबव्यूव यूबूटन के साथ एक होवरिंग पैनल है। सबव्यूव को 0.2 का अल्फा दिया जाता है, क्योंकि उपयोगकर्ता को इसके पीछे क्या देखने में सक्षम होना चाहिए।आईफोन एसडीके: पारदर्शी दृश्य में गैर-पारदर्शी सबव्यू

समस्या यह है कि जब मैं उप-दृश्य में यूबूटन जोड़ता हूं, तो वे सबव्यूव से अल्फा का उत्तराधिकारी होते हैं (मैं चाहता हूं कि बटन गैर-पारदर्शी हों और 1.0 का अल्फा हो)। मैंने इस समस्या से निपटने की कोशिश की है कि आप यूबूटन के माध्यम से पुन: प्रयास कर रहे हों और बिना सफलता के अपने अल्फा को 1.0 पर सेट कर सकें। समाधान की?

// Create the subview and add it to the view 
    topHoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
    topHoverView.backgroundColor = [UIColor blackColor]; 
    [topHoverView setAlpha:0.2]; 
    [self.view addSubview:topHoverView]; 

    // Add button 1 
    button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [button1 setFrame:CGRectMake(20, 10, 80, 30)]; 
    [button1 setTitle:@"New" forState:UIControlStateNormal]; 
    [button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside]; 
    [topHoverView addSubview:button1]; 

    // Add button 2 
    button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [button2 setFrame:CGRectMake(120, 10, 80, 30)]; 
    [button2 setTitle:@"Clear" forState:UIControlStateNormal]; 
    [button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside]; 
    [topHoverView addSubview:button2]; 

    // Add button 3 
    button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [button3 setFrame:CGRectMake(220, 10, 80, 30)]; 
    [button3 setTitle:@"Delete" forState:UIControlStateNormal]; 
    [button3 addTarget:self action:@selector(button3Action:) forControlEvents:UIControlEventTouchUpInside]; 
    [topHoverView addSubview:d button3]; 

    // Attempt to iterate through the subviews (buttons) to set their transparency back to 1.0 
    for (UIView *subView in topHoverView.subviews) { 
     subView.alpha = 1.0; 
    } 

उत्तर

15

आपको अल्फा 1.0 और पारदर्शी पृष्ठभूमि रंग के साथ शीर्ष होवर व्यू बनाना चाहिए। फिर एक काले रंग की पृष्ठभूमि अल्फा 0.2 के साथ पूरा दृश्य को शामिल किया गया है कि के साथ एक subview जोड़ने और फिर topHoverView बटन जोड़ने:

// Create the subview and add it to the view 
topHoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
topHoverView.backgroundColor = [UIColor transparentColor]; 
[topHoverView setAlpha:1.0]; 
[self.view addSubview:topHoverView]; 

canvasView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
canvasView.backgroundColor = [UIColor blackColor]; 
[canvasViewView setAlpha:0.2]; 
[topHoverView.view addSubview:canvasView]; 

// Add button 1 
button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button1 setFrame:CGRectMake(20, 10, 80, 30)]; 
[button1 setTitle:@"New" forState:UIControlStateNormal]; 
[button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside]; 
[topHoverView addSubview:button1]; 

// Add button 2 
button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button2 setFrame:CGRectMake(120, 10, 80, 30)]; 
[button2 setTitle:@"Clear" forState:UIControlStateNormal]; 
[button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside]; 
[topHoverView addSubview:button2]; 

// Add button 3 
button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button3 setFrame:CGRectMake(220, 10, 80, 30)]; 
[button3 setTitle:@"Delete" forState:UIControlStateNormal]; 
[button3 addTarget:self action:@selector(button3Action:) forControlEvents:UIControlEventTouchUpInside]; 
[topHoverView addSubview:d button3]; 

// Attempt to iterate through the subviews (buttons) to set their transparency back to 1.0 
for (UIView *subView in topHoverView.subviews) { 
    subView.alpha = 1.0; 
} 
+0

चीयर्स, अच्छा कामकाज। –

+0

फिलिप का धन्यवाद, मैं आईबी के अलावा एक जैसी चीज करने की कोशिश कर रहा था और मैं सिर्फ उस प्रभाव को प्राप्त करने में सक्षम नहीं था जिसे मैं चाहता था। लेकिन आपके कामकाज ने मुझे इसे पाने में मदद की। – sherry

6

बजाय

topHoverView.backgroundColor = [UIColor transparentColor]; 

, निम्नलिखित कोड सही है।

topHoverView.backgroundColor = [UIColor clearColor];