cocoa

Test if screensaver is running or workspace is locked

旧时模样 提交于 2020-01-15 06:22:12
问题 On Mac OS X, I know in Cocoa I can set up a observer for detecting future screen saver events or workspace lock events, like this: - (id)init { if ((self = [super init])) { NSDistributedNotificationCenter* distCenter = [NSDistributedNotificationCenter defaultCenter]; [distCenter addObserver:self selector:@selector(onScreenSaverStarted:) name:@"com.apple.screensaver.didstart" object:nil]; [distCenter addObserver:self selector:@selector(onScreenSaverStopped:) name:@"com.apple.screensaver

How To Draw More Precise Lines using Core Graphics and CALayer

守給你的承諾、 提交于 2020-01-15 05:43:07
问题 Hello I am having a hard time making this UI element look the way I want (see screenshot). Notice the image on the right--how the line width and darkness looks inconsistent compared to the image on the left (which happens to be a screen grab from safari) where the border width is more consistent. How does apple make their lines so perfect? I'm using a CALayer and the Core Graphics API to draw the image on the right. Is it possible to draw such perfect lines with the standard apis? 回答1: The

NSButton - Hit Testing rollover/hover for custom shaped buttons

霸气de小男生 提交于 2020-01-15 05:29:09
问题 (Targeting OS X 10.10, latest version of Xcode) I have an NSButton subclass. The button needs to respond to mouse rollovers/hovers, ala a web button. The button requires an appearance in the shape of a circle. Accordingly, -setImage: and -setAlternateImage: are called with circular-shaped graphics. Problem 1: the default behaviour of NSButton results in a positive hit-test when the mouse is clicked anywhere within the rect of the NSButton. This includes mouse clicks that are outside the

Display NSImage on a CALayer

眉间皱痕 提交于 2020-01-15 04:40:30
问题 I've been trying to display a NSImage on a CALayer. Then I realised I need to convert it to a CGImage apparently, then display it... I have this code which doesn't seem to be working CALayer *layer = [CALayer layer]; NSImage *finderIcon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kFinderIcon)]; [finderIcon setSize:(NSSize){ 128.0f, 128.0f }]; CGImageSourceRef source; source = CGImageSourceCreateWithData((CFDataRef)finderIcon, NULL); CGImageRef finalIcon =

Copy Files without freezing GUI

心不动则不痛 提交于 2020-01-15 04:13:30
问题 OK, so basically here's what I want to do : I have a list of files in my app bundle , e.g. in folder myData (please note: there are lots of files/folders within subfolders/etc) I want to copy the whole file tree to a given location on user's disk I need to have access to each separate file being copied, since some of them will need to be processed before being copied. How would you go about that? Any ideas? P.S. I know about NSFileWrapper 's writeFile:atomically:updateFilenames , but it doesn

What is the @package compiler directive for in Cocoa?

时光怂恿深爱的人放手 提交于 2020-01-15 03:57:06
问题 I see @package a lot in Apple's header files, but for the life of me, I can't find an authoritative source that describes its meaning. 回答1: @package is a scope declaration for a particular class member. There are four: @public : Accessible everywhere. @protected : Accessible within the class that defines it and inheriting classes. @private : Accessible within the class that defines it. @package : In 64-bit, like @public , but only within the same framework; in 32-bit, identical to @public .

Cocoa - Fade between two NSImage's?

不问归期 提交于 2020-01-14 18:55:15
问题 I have a menu with an NSImage showing some information, and when it gets updated I would like the new (updated) image to fade in. I know it is easy on the iPhone, but is this possible in OS X ? 回答1: It depends on how your menu is showing the image. If it's the menu item itself, this isn't possible without a lot of hackery. If you're using a custom NSView in the menu, then you can use two NSImageViews and swap between them using the view's -animator. You'd match imageViewB's frame to

Alternate audio tracks with HTTP Live Streaming

半世苍凉 提交于 2020-01-14 17:14:46
问题 I'm generating a list of available audio tracks when an HLS stream is ready to play. I can access the available audio tracks just fine, but I'm having difficulty extracting the correct 'Title' for each track. I'm using Apple's test stream which has two audio tracks. I extract the tracks with this... availableAudioTrackList = [[NSMutableArray alloc] init]; AVMediaSelectionGroup *audioTracks = [player.currentItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicAudible]; for

Alternate audio tracks with HTTP Live Streaming

雨燕双飞 提交于 2020-01-14 17:11:09
问题 I'm generating a list of available audio tracks when an HLS stream is ready to play. I can access the available audio tracks just fine, but I'm having difficulty extracting the correct 'Title' for each track. I'm using Apple's test stream which has two audio tracks. I extract the tracks with this... availableAudioTrackList = [[NSMutableArray alloc] init]; AVMediaSelectionGroup *audioTracks = [player.currentItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicAudible]; for

How to check a TCP port with Cocoa OSX SDK [closed]

青春壹個敷衍的年華 提交于 2020-01-14 16:44:57
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I would like to make a cocoa app that will check if some TCP ports are opened on a server. Return a little red ball if it's closed, or green if it's open... But I'm little bit confused, what class to use, etc.