2011-10-03 21 views
11

जोड़ा मेरे ऐप में मैं standardWindowButtons की स्थिति को बदलने तो जैसे करीब/miniturize/विस्तार से व्यवहार:कोको/OSX - NSWindow standardWindowButton अजीब एक बार की नकल की और फिर

//Create the buttons 
    NSButton *minitButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:window.styleMask]; 
NSButton *closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:window.styleMask]; 
NSButton *fullScreenButton = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:window.styleMask]; 


//set their location 
[closeButton setFrame:CGRectMake(7+70, window.frame.size.height - 22 - 52, closeButton.frame.size.width, closeButton.frame.size.height)]; 
[fullScreenButton setFrame:CGRectMake(47+70, window.frame.size.height - 22 -52, fullScreenButton.frame.size.width, fullScreenButton.frame.size.height)]; 
[minitButton setFrame:CGRectMake(27+70, window.frame.size.height - 22 - 52, minitButton.frame.size.width, minitButton.frame.size.height)]; 

//add them to the window 
[window.contentView addSubview:closeButton]; 
[window.contentView addSubview:fullScreenButton]; 
[window.contentView addSubview:minitButton]; 

अब जब खिड़की वहाँ बटन के साथ प्रकट होता है है दोनों समस्याओं: 1. वे ग्रे कर रहे हैं और न उनके सही रंग 2. जब माउस उन पर है कि वे + नहीं दिखा - या एक्स संकेत

किसी को भी मुझे बता सकते हैं मैं गलत क्या कर रहा हूँ। धन्यवाद।

उत्तर

-1

प्रत्येक बटन के लिए [button highlight:yes] पर कॉल करें।

+7

दुख की बात है '[बटन हाइलाइट: हाँ]' केवल विंडो बटन के "दबाए गए" राज्य ([संदर्भ] (http://www.cocoabuilder.com) को खींचता है /archive/cocoa/76398-standardwindowbuttons.html))। मुझे "होवर" राज्य खींचने के लिए अभी तक एक रास्ता नहीं पता है। – rentzsch

0

आप उन्हें फिर से नहीं जोड़ रहे हैं। आप उन्हें सामग्री पर ले जा रहे हैं देखें। बटन मूल रूप से window.contentView.superview में हैं।

[window.contentView.superview addSubview:closeButton]; 
[window.contentView.superview addSubview:fullScreenButton]; 
[window.contentView.superview addSubview:minitButton]; 

आपको ट्रैकिंग एरिया की आवश्यकता के बिना सही व्यवहार करना चाहिए।

10

यहां इस होवर जादू का यांत्रिकी है: मानक चक्र से चलने से पहले (जैसे NSWindowMiniaturizeButton) अपने superview अनियंत्रित विधि _mouseInGroup: पर कॉल करता है। यदि यह विधि YES लौटाती है तो घुमावदार बटन स्वयं आइकन के साथ खींचता है। बस इतना ही।

यदि आप इन बटनों को अपने स्वयं के दृश्य में रखते हैं, तो आप बस इस विधि को कार्यान्वित कर सकते हैं और इस माउस-होवर-उपस्थिति को अपनी इच्छानुसार नियंत्रित कर सकते हैं। यदि आप इन बटनों को बस स्थानांतरित या रिलाउट करते हैं और वे subviewNSThemeFrame (या कुछ समान) हैं, तो आपको इस कक्षा के लिए _mouseInGroup: विधि को तेज करना होगा, और शायद यह इसके लायक नहीं है क्योंकि हमारे पास पूरी तरह से सरल विधि है।

मेरे मामले में मैं कस्टम NSView कि subview रों के रूप में मेरे मानक बटन होते है और इस कोड को सब जादू ऊपर वर्णित करता है:

- (void)updateTrackingAreas 
{ 
    NSTrackingArea *const trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil]; 
    [self addTrackingArea:trackingArea]; 
} 

- (void)mouseEntered:(NSEvent *)event 
{ 
    [super mouseEntered:event]; 
    self.mouseInside = YES; 
    [self setNeedsDisplayForStandardWindowButtons]; 
} 

- (void)mouseExited:(NSEvent *)event 
{ 
    [super mouseExited:event]; 
    self.mouseInside = NO; 
    [self setNeedsDisplayForStandardWindowButtons]; 
} 

- (BOOL)_mouseInGroup:(NSButton *)button 
{ 
    return self.mouseInside; 
} 

- (void)setNeedsDisplayForStandardWindowButtons 
{ 
    [self.closeButtonView setNeedsDisplay]; 
    [self.miniaturizeButtonView setNeedsDisplay]; 
    [self.zoomButtonView setNeedsDisplay]; 
} 
1

मैं पूरी तरह से पता है कि इस सवाल का वर्ष और Valentin Shergin's answer है कर रहा हूँ सही। यह किसी भी निजी एपीआई के उपयोग को रोकता है, Google did in Chrome के विपरीत। सिर्फ उन बटनों को साझा करना चाहता था जो उप-वर्ग NSView की तरह महसूस नहीं करते हैं, बस उन बटनों को मौजूदा दृश्य में डालने के लिए (जैसे self.window.contentView)।

के रूप में मैं सिर्फ setFrame: के माध्यम से NSWindowButton रों स्थान बदलने के लिए चाहता था, मुझे पता चला है कि एक बार खिड़की था आकार दिया, ट्रैकिंग क्षेत्रों लगता है करने के लिए "ठीक" खुद स्वतः, किसी भी निजी एपीआई उपयोग बिना (कम से कम 10.11 में)।

इस प्रकार, आप निम्नलिखित तरह बातें लागू करने के लिए "नकली आकार बदलने" खिड़की है कि आप अपने बटन पुनर्निर्धारित करने के लिए कर सकते हैं:

NSRect frame = [self.window frame]; 
frame.size = NSMakeSize(frame.size.width, frame.size.height+1.f); 
[self.window setFrame:frame display:NO animate:NO]; 
frame.size = NSMakeSize(frame.size.width, frame.size.height-1.f); 
[self.window setFrame:frame display:NO animate:YES]; 

(मैं इसे अपने मुख्य विंडो के NSWindowDelegatewindowDidBecomeMain: भीतर था।जब तक खिड़की लोड हो और दृश्यमान दिखाई दे।)