core-graphics

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

Why is drawRect on MKOverlayRenderer slow

落花浮王杯 提交于 2020-01-15 04:50:10
问题 For an app, I have to place a MKCircle annotation on a MKMapView. However, the circle needs to be moved/resized. I know this has been asked, e.g. Moving MKCircle in MKMapView where removing/adding the annotation is suggested to get that behavior. However, I consider the drawing being very slow, like the user in this post: Smooth resizing of MKCircle. Since there are now answers to this question, the question seemed to use YHAnimatedCircleView . By slow I mean, when I use a UISlider to change

Is there an iOS equivalent of appendBezierPathWithArcWithCenter

ぃ、小莉子 提交于 2020-01-13 12:04:12
问题 I'm trying to draw a quarter circle in iOS. In Mac OS, it seems you can use appendBezierPathWithArcWithCenter but this doesn't seem to work in iOS. Does anyone know how to simply draw a quarter circle in iOS? Thanks 回答1: There are two iOS equivalents, one for UIBezierPath and one for CGPath : UIBezierPath equivalent UIBezierPath *path = [UIBezierPath bezierPath]; [path addArcWithCenter:centerPoint radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; CGPath equivalent

how to create a view like this shape in swift?

怎甘沉沦 提交于 2020-01-13 07:34:12
问题 how to create this 2D look How to I create this. Thanks a lot. 回答1: Try this class TwoDView : UIView { public var xDiff : CGFloat = 5.0 public var yDiff : CGFloat = 5.0 override func draw(_ rect: CGRect) { let ctx = UIGraphicsGetCurrentContext() ctx?.move(to: CGPoint(x: 0, y: rect.height - yDiff)) ctx?.addLines(between: [ CGPoint(x: rect.width - xDiff, y: rect.height - yDiff), CGPoint(x: rect.width, y: rect.height), CGPoint(x: xDiff, y: rect.height), CGPoint(x: 0, y: rect.height - yDiff) ])

How to animate fill color of path drawn with CGContextDrawPath, etc in drawRect:?

梦想与她 提交于 2020-01-13 06:48:48
问题 I wonder if is possible to animate the fill color of a path I have drawn using CoreGraphics? I am drawing this: Simple drawing with Quartz - Core Graphics and I want to change its fill color from white to let's say gray. Is this possible? I know the existence of view.layer.content property but Is this useful here? Though, I am not sure how can I use it in this case. Thanks in advance. Update I am trying this approach (its buggy, hence I can tell if its going to work) basically I am creating a

How to animate fill color of path drawn with CGContextDrawPath, etc in drawRect:?

早过忘川 提交于 2020-01-13 06:48:00
问题 I wonder if is possible to animate the fill color of a path I have drawn using CoreGraphics? I am drawing this: Simple drawing with Quartz - Core Graphics and I want to change its fill color from white to let's say gray. Is this possible? I know the existence of view.layer.content property but Is this useful here? Though, I am not sure how can I use it in this case. Thanks in advance. Update I am trying this approach (its buggy, hence I can tell if its going to work) basically I am creating a

how to make dashed line moveable

ⅰ亾dé卋堺 提交于 2020-01-13 05:10:50
问题 I used codes below to draw a dashed line // get the current CGContextRef for the view CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; // grab some useful view size numbers NSRect bounds = [self bounds]; float width = NSWidth( bounds ); float height = NSHeight( bounds ); float originX = NSMinX( bounds ); float originY = NSMinY( bounds ); float maxX = NSMaxX( bounds ); float maxY = NSMaxY( bounds ); float middleX = NSMidX( bounds ); float middleY =

Gradient effect for Line Graph in iPhone

家住魔仙堡 提交于 2020-01-13 03:55:14
问题 I'm trying to generate a graph with gradient/shading effect. Now I'm able to draw line graph and applied gradient effect to that graph. It is applying to whole view not to the graph. Now I'm getting image like this. But I want like this. I want gradient effect just under the graph. Please help me in this. Thanks in advance. The code that I'm using is: UIGraphicsBeginImageContext(self.graphView.frame.size); [graphView.image drawInRect:CGRectMake(0, 0, self.graphView.frame.size.width, self

drawing with clear color on UIView (cutting a hole) in static method

▼魔方 西西 提交于 2020-01-12 23:12:09
问题 I have an iPhone application and I need to implement the following method: +(UITextView *)textView:(UITextView *) withCuttedRect:(CGRect)r This method must cut (fill with [UIColor clearColor] ) the rect r from UITextView and return UITextView object. The user will see the view behind UITextView from the cutted holes. How can it be done? 回答1: When you would have something like: +(UITextView *)textView:(UITextView *)textView withCuttedRect:(CGRect)r { } you actually can simply access the

Mac OS X: Convert between NSView coordinates and global screen coordinates

此生再无相见时 提交于 2020-01-12 12:05:34
问题 I have the following situation in my multi-monitor setup: In this example I want to position a window exactly at the coordinates depicted with the yellow arrow. All I do have however, are the coordinates of an NSView that is a subview of the contentView of an NSWindow that spans the entire (bigger,upper) secondary monitor. Here's how the global coordinate space is defined: {0,0} is the coordinate of the upper left corner of my laptop screen. (green) {-296, -1080} is the coordinate of the