quartz-graphics

Sibling NSView z-ordering in Cocoa

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 10:21:34
问题 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

CGLayer and Anti-aliased CGPaths

末鹿安然 提交于 2019-12-07 09:40:11
问题 I am drawing several CGPaths in a Cocoa view in the drawRect method on an iPad. I started out drawing them straight to the UIGraphicsGetCurrentContext() context, but performance went south when my paths got really long. Based on several other questions, I started looking into using CGLayer s. So what I do now is to render a path inside of the CGContextRef I get from calling CGLayerGetContext . Here's the basic outline of what I'm doing: // rect comes from the drawRect: method layer =

Is it possible to to have more than one color in the same UILabel

假装没事ソ 提交于 2019-12-07 00:49:31
I want more than one font color in the same UILabel. I dont know if it is possible. I dont really think so but maybe some of you out there have a smart solution for it? Maybe something like stringWithFormat . [NSString stringWithFormatAndColor: @"Text with color: %@ %@", text, color, text, color] This image illustrate what I'm trying to accomplish: You can achieve this with NSAttributedSting. An easy to use drop-in replacement for UILabels with support for attributed strings is TTTAtributedLabel or OHAttributedLabel In my experience it is easier to work with NSMutableAttributedStrings and

Rendering UIImage/CGImage into CGPDFContext results in… blankness!

痴心易碎 提交于 2019-12-06 15:54:51
I'm trying to take an image that I have in a image object and render into a Core Graphics PDF context-- happens to be on an iPhone but this question surely applies equally to desktop Quartz. This UIImage is a simple color-on-white image at about 600x800 resolution. If I (say) turn it into a PNG file, that file looks exactly as expected-- so the data is OK. Here's what I'm doing to generate the PDF: NSMutableData * outputData = [[NSMutableData alloc] init]; CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData((CFMutableDataRef)outputData); CFMutableDictionaryRef attrDictionary = NULL

UIView infinite loop Animation to call a method after every repeat cycle

强颜欢笑 提交于 2019-12-06 15:34:55
I am at my wits end trying to come up with a design pattern for this paradigm. I haven't had much luck on this site but at this stage I'll try anything. I am trying to implement a radar type animation and hence I am rotating a view 360 degrees to represent the radius rotating around the circle. I have placed points around this circle and am able to calculate the angle from the center of the circle using standard trig. As the radius sweeps around the circle, if it intersects with a point (eg angle of the point equals the angle of the sweeping radius + a tolerance) the point flashes on. Now, I

CGContext Optimization

烂漫一生 提交于 2019-12-06 14:37:45
I have a small run speed problem. On load, I generate a CGMutablePath containing at least 1000 points. I want to scroll this path on the screen, so I use this kind of code : -(void) drawRect:(CGRect)rect { /* Here, I have a timer calling drawRect 60 times per second. There's also code for the scale and currentTime, based on an MP3 playback (AVAudioPlayer); */ CGContextRef ref = UIGraphicsGetCurrentContext(); CGContextClearRect(ref, [self frame]); CGContextSaveGState(ref); CGContextTranslateCTM(ref, s.width/2+currentTime, 1); CGContextScaleCTM(ref, scale, 1); CGContextAddPath(ref, myGraphPath);

How do I take a screenshot of a view which has transform?

纵然是瞬间 提交于 2019-12-06 14:17:53
问题 I'm able to crop a view with this code - (UIImage *)captureScreenInRect:(CGRect)captureFrame { CALayer *layer; layer = self.view.layer; UIGraphicsBeginImageContext(self.view.bounds.size); CGContextClipToRect (UIGraphicsGetCurrentContext(),captureFrame); [layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return screenImage; } But I have an imageview zoomed in with transform and it isn't shown

How can I draw a shadow beyond a UIView's bounds?

喜你入骨 提交于 2019-12-06 13:57:37
问题 I'm using the method described at How do I draw a shadow under a UIView? to draw shadow behind a view's content. The shadow is clipped to the view's bounds, although I disabled "Clip Subviews" in Interface Builder for the view. Is it possible to draw a shadow around a view and not only in a view? I don't want to draw the shadow inside the view because the view would receive touch events for the shadow area, which really belongs to the background. 回答1: It is not encouraged to draw outside view

Snap to grid effect with Quartz 2d? iphone dev

走远了吗. 提交于 2019-12-06 13:55:38
问题 Still an iphone dev starter but trying. I would like to have the user touch the screen at which point a pin (dot) will be placed on the view. I have accomplished this (yey) but i would like to have snap to grip effect, and can not come up with a solution. This is how i am placing that dot: CGPoint drawPoint = CGPointMake(lastTouch.x - horizontalOffset, lastTouch.y - >verticalOffset); [drawImage drawAtPoint:drawPoint]; //Tell the image to draw itself I have a grid as a background on a

Best practice of copying and serializing Quartz references

孤街醉人 提交于 2019-12-06 11:21:54
问题 I have objects containing Quartz-2D references (describing colors, fill patterns, gradients and shadows) in Cocoa. I would like to implement the NSCoding protocol in my objects and thus need to serialize those opaque Quartz-2D structures. Possible solutions might be: Define a set of properties in my objects that allow to setup the data structures from scratch whenever they are needed. Those can then be serialized easily. Example: Store four floats for red, green, blue, and alpha, then use