core-graphics

From CATransform3D to CGAffineTransform

戏子无情 提交于 2019-12-03 16:03:52
I'm using the following function to apply a pulse effect to a view - (void)pulse { CATransform3D trasform = CATransform3DScale(self.layer.transform, 1.15, 1.15, 1); trasform = CATransform3DRotate(trasform, angle, 0, 0, 0); CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; animation.toValue = [NSValue valueWithCATransform3D:trasform]; animation.autoreverses = YES; animation.duration = 0.3; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.repeatCount = 2; [self.layer addAnimation:animation forKey:

Point inside a rotated CGRect

前提是你 提交于 2019-12-03 15:41:25
How would you properly determine if a point is inside a rotated CGRect/frame? The frame is rotated with Core Graphics. So far I've found an algorithm that calculates if a point is inside a triangle, but that's not quite what I need. The frame being rotated is a regular UIView with a few subviews. Let's imagine that you use transform property to rotate a view: self.sampleView.transform = CGAffineTransformMakeRotation(M_PI_2 / 3.0); If you then have a gesture recognizer, for example, you can see if the user tapped in that location using locationInView with the rotated view, and it automatically

kCGColorSpaceGenericRGB is deprecated on iPhone?

会有一股神秘感。 提交于 2019-12-03 15:35:48
问题 I'm trying to get bitmap context with the following code: GContextRef MyCreateBitmapContext (int pixelsWide, int pixelsHigh) { CGContextRef context = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (pixelsWide * 4); // 1 bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);// 2 bitmapData = malloc( bitmapByteCount ); // 3 if (bitmapData == NULL) { fprintf

Can't draw in UITableViewCell's drawRect

≡放荡痞女 提交于 2019-12-03 15:04:22
I'm having trouble drawing in the drawRect method of my custom UITableViewCell. Here is the code I am using - (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGPoint origin = _faceView.frame.origin; CGFloat width = _faceView.frame.size.width; CGFloat height = _faceView.frame.size.height; CGFloat border = 2.0f; CGPoint startPt = CGPointMake(origin.x + width/2, self.frame.size.height); CGContextBeginPath(ctx); CGContextMoveToPoint(ctx, startPt.x, startPt.y); CGPoint basePt = CGPointMake(startPt.x, origin.y - height - border); CGContextAddLineToPoint(ctx, basePt.x,

Rounded rect with Gradient color

时光毁灭记忆、已成空白 提交于 2019-12-03 14:58:52
I have not really done much programming with Core Graphics. And I tend to stick with QuartzCore now that it does a lot of what I need through the layer property :) However, I have a UIView, which is currently gradient. I'd like to add rounded corners to this UIView and the layer property does not do this when I draw the gradient: - (void)drawRect:(CGRect)rect { CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGGradientRef glossGradient; CGColorSpaceRef rgbColorspace; size_t num_locations = 2; CGFloat locations[2] = { 0.0, 1.0 }; CGFloat components[8] = { 1.0, 1.0, 1.0, 0.95, //

CGDisplayCopyAllDisplayModes leaves out one valid mode

巧了我就是萌 提交于 2019-12-03 14:20:48
When programmatically working with display modes in OS X ( documentation ), I've found that the CGDisplayCopyAllDisplayModes leaves out the rightmost option that is presented in System Preferences. A simple utility that prints the size of the current display mode and all available display mode sizes outputs this current size: 1920x1200 available sizes: 2880x1800 1440x900 2560x1600 2048x1280 1024x768 800x600 640x480 1680x1050 1280x800 1920x1200 is a valid option All of the other options that System Preferences gives are represented in the list. Does anyone have any idea why 1920x1200 may not be

Only White Fill Color is Transparent in UIView

只愿长相守 提交于 2019-12-03 14:08:26
I've got a UIView that is set to opaque = NO and it all works nicely. In the drawRect I'm doing custom drawing, and this works CGContextSetFillColor(context, CGColorGetComponents([UIColor blueColor].CGColor)); CGContextFillRect(context, labelOutside); CGContextAddRect(context, labelOutside); but this CGContextSetFillColor(context, CGColorGetComponents([UIColor whiteColor].CGColor)); CGContextFillRect(context, labelOutside); CGContextAddRect(context, labelOutside); results in NO fill being produced (you can even see other stuff that I drew on the CGContext through it). How can I draw a white

Changing cornerRadius using Core Animation

孤街浪徒 提交于 2019-12-03 13:55:38
I am trying to change the corner radius of a button (OpenNoteVisible.layer) in the following way: CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"]; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; animation.fromValue = [NSNumber numberWithFloat:10.0f]; animation.toValue = [NSNumber numberWithFloat:0.0f]; animation.duration = 1.0; [animation.layer setCornerRadius:140.0]; [OpenNoteVisible.layer addAnimation:animation forKey:@"cornerRadius"]; But this code gives an error at the line [animation.layer

How to highlight CoreText with changing highlight colors?

℡╲_俬逩灬. 提交于 2019-12-03 13:48:40
问题 I have a subclass of UIView that implements code to draw CoreText. In the application, that UIView is drawn inside a UIScrollView. Here is the code that I currently use in drawRect: to render an NSAttributedString: CGContextRef context = UIGraphicsGetCurrentContext(); float viewHeight = self.bounds.size.height; CGContextTranslateCTM(context, 0, viewHeight); CGContextScaleCTM(context, 1.0, -1.0); CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, 1.0)); CGMutablePathRef path =

CGColorRef causing crash

痞子三分冷 提交于 2019-12-03 13:48:35
问题 I've had a crash in my code, and I've tracked it all the way back to a line crashing when being passed 2 CGColorRefs. Here are the objects: CGColorRef startColor = [[UIColor colorWithWhite:0.92 alpha:1.0]CGColor]; CGColorRef endColor = [[UIColor colorWithWhite:0.94 alpha:1.0]CGColor]; NSLog(@"start: %@ end: %@", startColor, endColor); The NSLog returns a crash. What's wrong with them? EDIT - where it's crashing: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[] =