core-graphics

What is the difference between closing the bezier path using closePath function and closing it manually?

≡放荡痞女 提交于 2019-12-03 13:46:50
I am trying to make a rectangle using UIBezierPath . I adopted two different ways to draw it. Also, I increased the stroke width to 25 px. First method : Using closePath UIBezierPath *bpath = [UIBezierPath bezierPath]; [bpath moveToPoint:CGPointMake(x, y)]; [bpath addLineToPoint:CGPointMake(x + w, y)]; [bpath addLineToPoint:CGPointMake(x + w, y + h)]; [bpath addLineToPoint:CGPointMake(x, y + h)]; [bpath closePath]; Output: Second method : Closing the path manually UIBezierPath *bpath = [UIBezierPath bezierPath]; [bpath moveToPoint:CGPointMake(x, y)]; [bpath addLineToPoint:CGPointMake(x + w, y)

How to resolve CGDirectDisplayID changing issues on newer multi-GPU Apple laptops in Core Foundation/IO Kit?

半腔热情 提交于 2019-12-03 13:33:44
问题 In Mac OS X, every display gets a unique CGDirectDisplayID number assigned to it. You can use CGGetActiveDisplayList( ) or [NSScreen screens] to access them, among others. Per Apple's docs: A display ID can persist across processes and system reboot, and typically remains constant as long as certain display parameters do not change. On newer mid-2010 MacBook Pro's, Apple started using auto-switching Intel/nVidia graphics. Laptops have two GPU's, a low-powered Intel, and a high-powered nVidia.

Erase and un erase a image in UIImageVIew with touch using coregraphics

你说的曾经没有我的故事 提交于 2019-12-03 13:25:49
问题 My question is same as mentioned at here. I'm also using two images in my app and all I need is to erase a top image by touch. Then un-erase (if required) the erased part by touch. I'm using following code to erase the the top image. There is also a problem in this approach. Which is that the images are big and I'm using Aspect Fit content mode to properly display them. When I touch on the screen, it erase in the corner not the touched place. I think the touch point calculation is required

Force clockwise/anticlockwise rotation for a CABasicAnimation of a UIImageView

回眸只為那壹抹淺笑 提交于 2019-12-03 13:10:06
I'm animating a pendulum which swings from 0 degrees to max 200 degrees and then back again. The problem is that if the pendulum goes over 180 degrees, it returns to 0 by the shortest route which is to continue clockwise. And I'd like it to go anticlockwise. Here's my code: ('right' is a boolean which is TRUE when the pendulum is swinging from left to right) - (void)swingPendulum { CABasicAnimation *rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; if (right) rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(kMax)];

OSX/Swift: Call function when screen becomes available

徘徊边缘 提交于 2019-12-03 12:27:15
I want my OSX app to call a function when the user's screen becomes available, ex: their computer wakes from sleep or the user turns on their screen. Basically any time the user goes from having no screen active to having one active, I would like my function to be called. I'm not sure if the best way to do this is to: Check for changes in sleep/wake state or Use CGDisplayReconfigurationCallback or Listen for a NSWorkspaceScreensDidWakeNotification Which of these seems like the best way to do this, or should I do something else entirely? Some kind of example Swift code would be really helpful

iOS: create an darker version of UIImage and leave transparent pixels unchanged?

六月ゝ 毕业季﹏ 提交于 2019-12-03 11:58:39
问题 I found Create new UIImage by adding shadow to existing UIImage and UIImage, is there an easy way to make it darker or all black But the selected answers do not work for me. I have an UIImage, which may have some transparent pixels in it, I need to create a new UIImage with non-transparent pixels darkened, is there any way to do this? I was thinking of using UIBezierPath but I don't know how to do it for only non-transparent pixels. 回答1: This is the class I use to color images even if they

Bitwise operations with CGBitmapInfo and CGImageAlphaInfo

梦想与她 提交于 2019-12-03 11:51:05
I'm having trouble performing bitwise operations with CGImageAlphaInfo and CGBitmapInfo in Swift. In particular, I don't know how to port this Objective-C code: bitmapInfo &= ~kCGBitmapAlphaInfoMask; bitmapInfo |= kCGImageAlphaNoneSkipFirst; The following straightforward Swift port produces the somewhat cryptic compiler error 'CGBitmapInfo' is not identical to 'Bool' on the last line: bitmapInfo &= ~CGBitmapInfo.AlphaInfoMask bitmapInfo |= CGImageAlphaInfo.NoneSkipFirst Looking at the source code I noticed that CGBitmapInfo is declared as a RawOptionSetType while CGImageAlphaInfo isn't. Maybe

Why use functions like CGRectMake?

你离开我真会死。 提交于 2019-12-03 10:57:06
I'm curious why functions like CGRectMake and CGPointMake exist and are widely used. when, instead, you can do: (CGRect){{x, y}, {width, height}} surely this is more efficient (though I'm guessing not by much) as there is no function call? Also you can set the origin and size like: (CGRect){origin, size} and as a mixture: (CGRect){origin, {width, height}} What is the reason for not using this, and preferring the Make functions? Kalle It isn't more efficient, actually. The CGRectMake function (and others) are declared as static inline , which means the compiler copy pastes the function code

UIGraphicsBeginImageContext vs CGBitmapContextCreate on iOS

醉酒当歌 提交于 2019-12-03 10:56:13
This may be a really stupid question, but can someone tell me the difference between creating a CGContextRef using UIGraphicsBeginImageContext and using CGBitmapContextCreate for drawing to images? Especially now since UIKit drawing is thread safe I was wondering if there was any reason to use CGBitmapContextCreate over UIGraphicsBeginImageContext. According to Apple's UIKit Function Reference , which carries the cover date of the 15th November 2010, UIGraphicsBeginImageContext and related functions should still be called on the main thread only. The same text is repeated in the developer

Drawing text over Core Graphics in Swift 3

不羁岁月 提交于 2019-12-03 10:18:12
Background: I am drawing on a UIImageView with Core Graphics. I would like to ultimately draw a text string over the core graphics drawing. This (hackingwithswift.com) method i used to draw the text to an image, set my imageView to that image, and then draw over with core graphics. But I want the text to overlay the core graphics drawing. Now I have moved to this https://stackoverflow.com/a/35574171/6337391 but it still isnt allowing me to write on top of my drawing. class MapViewController: UIViewController { @IBOutlet var imageView: UIImageView! func drawScale() { // establish 6 points to