quartz-graphics

Using CGEventTapCreate Trouble with parameters in Swift

百般思念 提交于 2019-12-06 07:57:20
I am trying to trap keypresses using a CGEventTapCreate etc in Swift. I want to do this so that when my toddler is using a program the Mac, I can limit which keys do something. I appreciate that I need to enable assistive technology to get CGEventTap to work I am having trouble understanding what I need to do in Swift to get the final parameter in the call. Essentially, I do not understand part of the documentation at quartz event documentation Specifically the final parameter which is described by refcon: A pointer to user-defined data. This pointer is passed into the callback function

Does CGContextSetTextMatrix work for offscreen bitmaps?

青春壹個敷衍的年華 提交于 2019-12-06 07:23:17
I'm creating an image offscreen using a context from CGBitmapContextCreate() . While drawing text, I tried to use the: CGContextSetTextMatrix(contextRef, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); but my text was still upside down. If I used the standard transforms it was correct: CGContextTranslateCTM(contextRef, 0.0, contextRect.size.height); CGContextScaleCTM(contextRef, 1.0, -1.0); My question is should the CGContextSetTextMatrix work for an offscreen bitmap? Maybe I was doing something wrong. No. The text matrix, as its name says, only affects text. All drawing goes through

Drawing the blue “unread dot” on the iPhone Mail app

久未见 提交于 2019-12-06 06:26:46
Does anyone have an example of how to draw the blue "unread dot" used in Apple's Mail App? This one in specific: Drawing an ellipse is straight forward with Quartz2d, but the subtle use of shadows+gradients make this look really 3d. I think the blue dot in mail is actually an image; I would imagine that blitting an image would be faster than drawing a gradient. If you decide to go with a resource there is an app called UIKit-Artwork-Extractor that allows you to rip all the resources from all the IOS apps you have installed https://github.com/0xced/UIKit-Artwork-Extractor 来源: https:/

Sluggish scrolling experience when using QuartzCore to round corners on UIImageView's within a UITableViewCell

放肆的年华 提交于 2019-12-06 04:01:20
问题 I use QuartzCore to add rounded corners to my UIImageView 's within the cells of my UITableView This is the code that I use: fooImageView.layer.cornerRadius = 9.0; fooImageView.layer.masksToBounds = YES; fooImageView.layer.borderWidth = 1.0; The problem is that when I add this code. The table cells movement is slowed down dramatically. I'm just wondering whether there are other alternatives to make the user experience much faster and to increase performance when scrolling a table view cell

UIImagePNGRepresentation and masked images

こ雲淡風輕ζ 提交于 2019-12-06 02:59:56
I created a masked image using a function form an iphone blog: UIImage *imgToSave = [self maskImage:[UIImage imageNamed:@"pic.jpg"] withMask:[UIImage imageNamed:@"sd-face-mask.png"]]; Looks good in a UIImageView UIImageView *imgView = [[UIImageView alloc] initWithImage:imgToSave]; imgView.center = CGPointMake(160.0f, 140.0f); [self.view addSubview:imgView]; UIImagePNGRepresentation to save to disk : [UIImagePNGRepresentation(imgToSave) writeToFile:[self findUniqueSavePath] atomically:YES]; UIImagePNGRepresentation returns NSData of an image that looks different. The output is inverse image

How do I remove those rotation artefacts from my CATiledLayer?

雨燕双飞 提交于 2019-12-06 00:28:52
问题 I have a CATiledLayer into which I render content in the following method - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx I used the QuartzDemo code to draw a pattern. This works very well until I apply a rotation transform to the layer's parentLayer (a UIView): rotated: These zigzag artefacts become worse when I start drawing lines and texts into the CATiledLayer. I applied the transform as follows (I also tried using an affine transform on the view itself): self.containerView

How to determine and interpret the pixel format of a CGImage

半世苍凉 提交于 2019-12-06 00:09:36
问题 I'm loading this (very small) image using: UIImage* image = [UIImage named:@"someFile.png"]; The image is 4x1 and it contains a red, green, blue and white pixel from left to right, in that order. Next, I get the pixel data out of the underlying CGImage: NSData* data = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)); Now, for some reason, the pixel data is laid out differently depending on the iOS device. When I run the app in the simulator or on my iPhone 4, the pixel

CALayer vs. drawInRect: performance?

别来无恙 提交于 2019-12-06 00:05:48
I'm trying to draw some shadows in a rect. The shadow image itself is about 1px * 26px. Here's two methods I've thought of for drawing the image in the view: //These methods are called in drawRect: /* Method 1 */ [self.upperShadow drawInRect:rectHigh]; //upperShadow is UIImage [self.lowerShadow drawInRect:rectLow]; /* Method 2 */ CALayer *shadowTop = [CALayer layer]; shadowTop.frame = rectHigh; shadowTop.contents = (__bridge id)topShadow; //topShadow is CGImage [self.layer addSublayer:shadowTop]; CALayer *shadowLow = [CALayer layer]; shadowLow.frame = rectLow; shadowLow.contents = (__bridge id

Is it possible to detect if Magic Mouse/Trackpad is being touched?

心已入冬 提交于 2019-12-05 22:41:25
Just wondering if there is a way to receive a callback in Cocoa if Magic Mouse or Trackpad is being touched by the user? I looked into Quartz Events, but it seems I can only get callbacks if the mouse is moving or clicked etc. Note that I want to receive a callback even if my app is not active. It's a background utility app. Also, it can't use private frameworks as it's going to be a Mac App Store app. alecail You could use this code to trap the events: (create a new Cocoa application and put this in the application delegate) NSEventMask eventMask = NSEventMaskGesture | NSEventMaskMagnify |

Sibling NSView z-ordering in Cocoa

↘锁芯ラ 提交于 2019-12-05 19:29:27
How does z-ordering work with sibling NSViews in Cocoa? I'm confused because I'm finding conflicting sources of information in Apple's docs and APIs. (Note: Subviews are obviously rendered on top of its parent view, I am talking explicitly about sibling views here). Hypothesis A : "Yes, you can define the z-order of sibling NSViews " In IB you can place views on top of each other and they will always be composited in the way you'd expect. There's buttons in Xcode under the Editor menu named "Send to Back", "Send Forward" etc. The NSView also has a method named - (void)addSubview:(NSView *