quartz-graphics

Performing a double click using CGEventCreateMouseEvent()

我与影子孤独终老i 提交于 2019-11-26 19:38:05
问题 I'm using the following code to simulate a click of the mouse: void PostMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point) { CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button); CGEventSetType(theEvent, type); CGEventPost(kCGHIDEventTap, theEvent); CFRelease(theEvent); } void LeftClick(const CGPoint point) { PostMouseEvent(kCGMouseButtonLeft, kCGEventMouseMoved, point); NSLog(@"Click!"); PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseDown, point)

UIImageWriteToSavedPhotosAlbum save as PNG with transparency?

末鹿安然 提交于 2019-11-26 19:29:29
问题 I'm using UIImageWriteToSavedPhotosAlbum to save a UIImage to the user's photo album. The problem is that the image doesn't have transparency and is a JPG. I've got the pixel data set correctly to have transparency, but there doesn't seem to be a way to save in a transparency-supported format. Ideas? EDIT: There is no way to accomplish this, however there are other ways to deliver PNG images to the user. One of which is to save the image in the Documents directory (as detailed below). Once

Applying a Gradient to CAShapeLayer

。_饼干妹妹 提交于 2019-11-26 19:24:09
问题 Does anyone have any experience in applying a Gradient to a CAShapeLayer? CAShapeLayer is a fantastic layer class, but it appears to only support solid fill coloring, whereas I'd like it to have a gradient fill (actually an animatable gradient at that). Everything else to do with CAShapeLayer (shadows, shapes, stroke color, animatable shape path) is fantastic. I've tried placing a CAGradientLayer inside a CAShapeLayer, or indeed setting the CAShapeLayer as the mask of the GradientLayer and

Curve text on existing circle

末鹿安然 提交于 2019-11-26 18:12:22
For an application I am building I have drawn 2 circles. One a bit bigger than the other. I want to curve text between those lines, for a circular menu I am building. I read most stuff about curving a text that you have to split up your text in characters and draw each character on it's own with the right angle in mind (by rotating the context you are drawing on). I just can't wrap my head around on how to get the right angles and positions for my characters. I included a screenshot on what the menu, at the moment, look like. Only the texts I added by are loaded from an image in an UIImageView

How to convert ASCII character to CGKeyCode?

女生的网名这么多〃 提交于 2019-11-26 16:06:19
I need a function that, given a character, returns the CGKeyCode associated with the position of that character on the current keyboard layout. E.g., given "b", it should return kVK_ANSI_B if using U.S. QWERTY, or kVK_ANSI_N if using Dvorak. The Win32 API has the function VkKeyScan() for this purpose; X11 has the function XStringToKeySym() . Is there such a function in the CG API? I need this in order to pass a parameter to CGEventCreateKeyboardEvent() . I've tried using CGEventKeyboardSetUnicodeString() instead, but that apparently does not support modifier flags (which I need). I have

How to create a UIImage from the current graphics context?

浪尽此生 提交于 2019-11-26 15:59:55
问题 I'd like to create a UIImage object from the current graphics context. More specifically, my use case is a view that the user can draw lines on. They may draw incrementally. After they are done, I'd like to create a UIImage to represent their drawing. Here is what drawRect: looks like for me now: - (void)drawRect:(CGRect)rect { CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSaveGState(c); CGContextSetStrokeColorWithColor(c, [UIColor blackColor].CGColor); CGContextSetLineWidth(c,1.5f

Is there a way to make drawRect work right NOW?

烂漫一生 提交于 2019-11-26 15:47:17
The original question............................................... If you are an advanced user of drawRect, you will know that of course drawRect will not actually run until "all processing is finished." setNeedsDisplay flags a view as invalidated and the OS, and basically waits until all processing is done. This can be infuriating in the common situation where you want to have: a view controller 1 starts some function 2 which incrementally 3 creates a more and more complicated artwork and 4 at each step, you setNeedsDisplay (wrong!) 5 until all the work is done 6 Of course, when you do the

Can't add a corner radius and a shadow

瘦欲@ 提交于 2019-11-26 15:21:29
问题 I'm trying to draw a shadow and a corner radius on an image. I can add them separately, but I've got no way to add both effects at the same time. I'm adding a shadow with: [layer setShadowOffset:CGSizeMake(0, 3)]; [layer setShadowOpacity:0.4]; [layer setShadowRadius:3.0f]; [layer setShouldRasterize:YES]; Here, layer is a CALayer of a UIView subclass. So this works whenever I set [layer setMasksToBounds:NO]; Now to add a corner radius I do this: [layer setCornerRadius:7.0f]; but I need to set

Where can I find a list of Mac virtual key codes?

妖精的绣舞 提交于 2019-11-26 14:54:43
I'm using CGEventCreateKeyboardEvent and need to know what CGKeyCode values to use. Specifically, I am after the key code for the Command key. The docs give examples for other keys: z is 6 , shift is 56 . There must be a list of Mac virtual keycodes somewhere? Matt B. The more canonical reference is in <HIToolbox/Events.h> : /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h In newer Versions of MacOS the "Events.h" moved to here: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework

How do I draw a line on the iPhone?

匆匆过客 提交于 2019-11-26 12:59:21
I am a beginner at iPhone programming, and would like to draw a line to the phone screen for the purpose of study using Quartz and UIKit. How do I start drawing? The first step is to define a subclass of UIView, to create a space to draw in. If you're starting with a new application, the easiest way will be to start with the "Window-based application" template. Then go New File and create an "Objective-C Class" with "Subclass of" set to "UIView", and give it a name, say MyView.m. Now open up the "Resources" group and double click on "MainWindow.xib" to open it in Interface Builder. From here