core-animation

How to animate the drawing of a CGPath?

ⅰ亾dé卋堺 提交于 2020-01-22 09:46:26
问题 I am wondering if there is a way to do this using Core Animation. Specifically, I am adding a sub-layer to a layer-backed custom NSView and setting its delegate to another custom NSView. That class's drawInRect method draws a single CGPath: - (void)drawInRect:(CGRect)rect inContext:(CGContextRef)context { CGContextSaveGState(context); CGContextSetLineWidth(context, 12); CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddLineToPoint(path, NULL, rect

Are layer-backed NSView siblings allowed to overlap?

放肆的年华 提交于 2020-01-19 07:58:40
问题 I'm a little confused. The Apple Documentation states this: Note: For performance reasons, Cocoa does not enforce clipping among sibling views or guarantee correct invalidation and drawing behavior when sibling views overlap. If you want a view to be drawn in front of another view, you should make the front view a subview (or descendant) of the rear view. So according to this, sibling views should not overlap or else the behavior is undefined. In the Cocoa Slides demo app, however, layer

CADisplayLink stops updating when UIScrollView scrolled

旧街凉风 提交于 2020-01-19 05:16:11
问题 Title is quite self explanatory, but I have some animation being done in a loop triggered by CADisplayLink. However, as soon as I scroll a UIScrollView I have added to my view hierarchy, the animation stops immediately, only to return again when scrolling has completely stopped and come to a standstill.... Anyway to cancel this behaviour? 回答1: Run the display link (using -addToRunLoop:forMode: ) on another thread with another run loop. So create a new thread, create a run loop on that thread,

Shake visual effect on iPhone (NOT shaking the device)

为君一笑 提交于 2020-01-19 01:55:46
问题 On login failure, I'd prefer to avoid showing an alert, it's too fleeting. Showing the alert and then showing the text somewhere on the login screen seems like duplication. So I'd like for it to graphically shake my login view when the user enters the wrong user ID and password like the Mac login screen does. Anyone know if there's a way to pull this off, or have any suggestions for another effect I could use? 回答1: I think this is a more efficient solution: Swift: let anim =

Gradient Layer over ImageView reuse

こ雲淡風輕ζ 提交于 2020-01-17 05:37:31
问题 Within my 'cellForRowAtIndexPath' I have the following code to populate the image (async) and apply a custom gradient This worked fine, until I added a custom colour per cell. What it's currently doing is recycling the previous colour rather than applying a new one - this is presumably due to the following line which will skip the gradient code once applied to each cell: if(!cell.gradientMask){ However, if I comment this out, the colours work but the gradient on each cell will stack up as a

Cocoa - Fade between two NSImage's?

不问归期 提交于 2020-01-14 18:55:15
问题 I have a menu with an NSImage showing some information, and when it gets updated I would like the new (updated) image to fade in. I know it is easy on the iPhone, but is this possible in OS X ? 回答1: It depends on how your menu is showing the image. If it's the menu item itself, this isn't possible without a lot of hackery. If you're using a custom NSView in the menu, then you can use two NSImageViews and swap between them using the view's -animator. You'd match imageViewB's frame to

CAShapeLayer path animation — shrinking a circle

混江龙づ霸主 提交于 2020-01-14 05:40:11
问题 I'm trying to shrink a circular CAShapeLayer but using the key path 'path' does not seem to be working. CGPathRef startPath = [UIBezierPath bezierPathWithOvalInRect:startRect].CGPath; CGPathRef endPath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(startRect, 15, 15)].CGPath; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"]; animation.duration = 1.0; animation.fromValue = (__bridge id)startPath; animation.toValue = (__bridge id)endPath; animation

Blink hidden and using blocks

ⅰ亾dé卋堺 提交于 2020-01-14 05:20:07
问题 I have the method: - (void)blinkView:(UIView *)view { view.layer.opacity = 0.0f; view.hidden = NO; [UIView beginAnimations:@"Blinking" context:nil]; [UIView setAnimationRepeatCount:1.0]; [UIView setAnimationDuration:0.6f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; view.layer.opacity = 1.0f; [UIView commitAnimations]; } How can i write this code with blocks, and how i must implement method with reverse effect (hide uiview with blink) ? 回答1: [UIView transitionWithView: view

Is it possible to persist the contents of a CALayer between drawInContext calls?

我的梦境 提交于 2020-01-14 04:52:42
问题 Are there any built in abilities to maintain the contents of a CALayer between drawLayer:inContext: calls? Right now I am copying the layer to a buffer and redrawing an image from the buffer every time I called back in drawLayer:inContext: but I'm wondering if CALayer has a way to do this automatically... 回答1: I don't believe so. The 'drawInContext' will clear the underlying buffer so that you can draw to it. However, if you forego the drawInContext or drawRect methods, you can set your layer

Core Animation implicit animation doesn't fire for newly added sublayer

蹲街弑〆低调 提交于 2020-01-14 03:43:27
问题 Don't know why this doesn't work. I can't do implicit animation for a newly added sublayer until some even triggers it like a button push or being called from another method. This here below doesn't animate even though I think i should. It just shows the 'after' state of the layer. CAGradientLayer *newBar = [CAGradientLayer layer]; CGFloat barHeight = ((pair.amount.floatValue/self.model.maxModelValue.floatValue)*maxBarHeight); newBar.bounds=R(0,0,self.barWidth,0); newBar.anchorPoint=P(0, 1);