quartz-graphics

UIView with shadow

偶尔善良 提交于 2019-12-03 03:04:19
I'm trying to create a shadow around a simple UIView object which is added on top of a UIViewController's view. what's the most straight forward way of doing this? Ned First, be sure to import the Quartz Core library: #import <QuartzCore/QuartzCore.h> Next, add the following lines to set up the shadow's properties: someView.layer.shadowColor = [[UIColor blackColor] CGColor]; someView.layer.shadowOffset = CGSizeMake(10.0f,10.0f); someView.layer.shadowOpacity = .5f; someView.layer.shadowRadius = 10.0f; Keep in mind that if you have that view's clipsToBounds property set to YES, the shadow won't

How do I create a grid of icons like the iPhone home screen?

拈花ヽ惹草 提交于 2019-12-03 01:45:26
问题 How should I go about creating a UI similar to the Springboard (home screen) on the iPhone? I'd like a grid of evenly spaced buttons with images where I can respond to the button tap. Is the UITable a good fit? Should I use a plain UIView and position the icons manually in DrawRect? Is there an alternative that will automatically evenly space the buttons, allow reorganization, and adjust the layout according to the iPhone orientation? I come from a C#/Winforms background and am just now

iOS: Improving speed of image drawing

人盡茶涼 提交于 2019-12-03 00:42:38
I have a sequence of images that I want to animate ( UIImageView supports some basic animation but it's not sufficient for my needs). My first approach was to use UIImageView and set the image property when the image. This was too slow. The reason for the poor speed was due to the drawing of the images (which surprised me; I assumed the bottle neck would be loading the image). My second approach was to use a generic UIView and set view.layer.contents = image.CGImage . This gave no noticeable improvement. Both of these approaches must be performed on the main thread. I think the poor speed is

Optimizing a drawing (with finger touches) application for iPhone SDK

☆樱花仙子☆ 提交于 2019-12-03 00:37:00
I'm writing an application that uses your finger to draw simple diagrams. I have it working for the most part but now I'm trying to optimize its performance. When the user swipes their finger fast, I can't capture enough touch events to draw a smooth path. Here's my current approach: 1) I subclassed a UIView and added a poroperty to a CGLayer (gets created lazily and is the same size as my UIView). 2) My UIView subclass responds to touch events by storing the current and last touch points in instance variables. 3) My view's setNeedsDisplay is called and in the draw rect , do the following: -

Change animation time for properties of a CALayer

烈酒焚心 提交于 2019-12-03 00:21:13
I have a CALayer to animate a change in its image contents. Now, how can I change how long it takes for this animation to take place? papr It's more or less simple. You have an ivar CALayer *yourLayer . Then you set the delegate and implement the delegate method -(id<CAAction>)actionForLayer:forKey: - (void)awakeFromNib { yourLayer.delegate = self; yourLayer.name = @"yourLayer"; } - (id <CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event { if([layer.name isEqualToString yourLayer.name]) { // Check for right layer CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath

Draw a perfect circle from user's touch

不问归期 提交于 2019-12-03 00:01:47
问题 I have this practice project that allows the user to draw on the screen as they touch with their fingers. Very simple App I did as exercise way back. My little cousin took the liberty of drawing things with his finger with my iPad on this App (Kids drawings: circle, lines, etc, whatever came to his mind). Then he started to draw circles and then he asked me to make it "good circle" (from my understanding: make the drawn circle perfectly round, as we know no matter how stable we try to draw

How to add a CALayer to an NSView on Mac OS X

核能气质少年 提交于 2019-12-02 20:33:50
I'm trying to learn how to use and implement CALayer in a Mac Objective-C application, but I can't seem to probably do the most basic thing - add a new layer and set its background colour/frame size. Can anyone see what is wrong with my code? CALayer *layer = [CALayer layer]; [layer setFrame:CGRectMake(0, 0, 100, 100)]; [layer setBackgroundColor:CGColorCreateGenericRGB(1.0, 0.0, 0.0, 1.0)]; [self.layer addSublayer:layer]; [layer display]; I put this in the - (void)drawRect:(NSRect)rect method of my custom NSView subclass, but when I run the application, it just shows a blank view, with no

Beginner iphone question: drawing a rectangle. What am I doing wrong?

随声附和 提交于 2019-12-02 19:45:10
Trying to figure out what I'm doing wrong here. Have tried several things, but I never see that elusive rectangle on the screen. Right now, that's all I want to do -- just draw a single rectangle on the screen. I'm getting an "invalid context" on everything but the CGContextSetRGBFillColor(). Getting the context after that seems kinda wrong to me, but I'm not at home looking at the examples I was using last night. Have I messed up something else as well? I really would like to get at least this much done tonight... - (id)initWithCoder:(NSCoder *)coder { CGRect myRect; CGPoint myPoint; CGSize

GLPaint save image

梦想的初衷 提交于 2019-12-02 18:55:38
I'm trying to develop a complex painting application on the iPhone. I'm currently drawing using Quartz (e.g. CGContext ...). Unfortunately the Quartz overhead is just too slow for the type of drawing I'm doing, and I'm porting to OpenGL calls using the GLPaint example as a reference point. Is there a way to get a UIImage/CGImage from the EAGLview class (the equivalent of Quartz's UIGraphicsGetImageFromCurrentImageContext )? Basically I need to save the pictures drawn by the GLPaint application. -(UIImage *) saveImageFromGLView { NSInteger myDataLength = 320 * 480 * 4; // allocate array and

Drawing animation

徘徊边缘 提交于 2019-12-02 18:38:09
I'm creating a simple app where when the user presses a button, a series of lines will be drawn on the screen and the user will be able to see these lines drawn in real time (almost like an animation). My code looks something like this (has been simplified): UIGraphicsBeginImageContext(CGSizeMake(300,300)); CGContextRef context = UIGraphicsGetCurrentContext(); for (int i = 0; i < 100; i++ ) { CGContextMoveToPoint(context, i, i); CGContextAddLineToPoint(context, i+20, i+20); CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]); CGContextStrokePath(context); } UIImage