core-animation

How to inherit animation properties while animating CALayer with implicit animation

我是研究僧i 提交于 2020-01-12 07:36:14
问题 I am trying to animate a custom property on a CALayer with an implicit animation: [UIView animateWithDuration:2.0f animations:^{ self.imageView.myLayer.myProperty = 1; }]; In -actionForKey: method I need to return the animation taking care of interpolating the values. Of course I have to tell somehow the animation how to retrieve the other parameters for the animation (i.e. the duration and the timing function ). - (id<CAAction>)actionForKey:(NSString *)event { if ([event isEqualToString:@

Trim/subtract CGPath from CGPath?

你离开我真会死。 提交于 2020-01-12 03:26:08
问题 I have some CGPath (a poly with two circle) carried out on a CAShapeLayer . Can I trim/subtract paths like this? 回答1: Instead of do the math, the result can be achieved at drawing time using kCGBlendModeClear . // Create the poly. CGContextBeginPath(context); CGContextMoveToPoint (context, a_.x, a_.y); CGContextAddLineToPoint (context, b_.x, b_.y); CGContextAddLineToPoint (context, c_.x, c_.y); CGContextAddLineToPoint (context, d_.x, d_.y); CGContextClosePath(context); // Draw with the

Animate UIButton's title change

ぃ、小莉子 提交于 2020-01-11 20:09:39
问题 Here I found how to animate UIButton 's title change using now-deprecated beginAnimations:context: method: UIBUtton title animation for iPhone How to do the same thing using current APIs? Update: I've tried to use block-based animations: NSTimeInterval animationDuration = animated ? 1.f : 0.f; [UIView animateWithDuration:animationDuration delay:0.f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{ [button setTitle:newTitle forState

Animate UIButton's title change

 ̄綄美尐妖づ 提交于 2020-01-11 20:09:30
问题 Here I found how to animate UIButton 's title change using now-deprecated beginAnimations:context: method: UIBUtton title animation for iPhone How to do the same thing using current APIs? Update: I've tried to use block-based animations: NSTimeInterval animationDuration = animated ? 1.f : 0.f; [UIView animateWithDuration:animationDuration delay:0.f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{ [button setTitle:newTitle forState

Create masking effect over a view

蹲街弑〆低调 提交于 2020-01-11 07:12:10
问题 I would like to create a masking effect over a UIView in order to accomplish the following. I will display a sealed box in the screen and the user will be able to touch (scratch) the screen in order to reveal whats behind that image(UIView). Something similar to those lottery tickets where u r suppose to scratch some cover material thats on top of the results.. If someone could point me in the right direction would be awesome, I'm not sure how to start doing this... thanks 回答1: Sorry I'm late

How to sequence two animations with delay in between

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 05:25:50
问题 I have a UIImageView which i want to rotate 180 degrees, taking up 1 second, then i want to wait 1 second at this position, then rotate 180 degrees back to the original position taking up 1 second. How do i accomplish this? I've tried a 100 approaches and it keeps snapping back instead of rotating back EDIT: I forgot to add i need this to repeat indefinitely 回答1: You can perform the second animation in the completionHandler presented on UIView.animate let duration = self.transitionDuration

How to dim os x desktop using Cocoa/Core Animation

跟風遠走 提交于 2020-01-10 20:01:14
问题 Is there a way to control the brightness of the OS X desktop programmatically using Cocoa or Core Animation? 回答1: In case you were actually interested in doing a fade-out or fade-in of the whole screen, here is a link describing how to do that. The linked document contains examples for how to fade all displays (or a single display) to black (you can change the color), capture the display (where you can display what you'd like), and then fade back. This uses CGAcquireDisplayFadeReservation()

How to Animate CoreGraphics Drawing of Shape Using CAKeyframeAnimation

ⅰ亾dé卋堺 提交于 2020-01-10 10:51:03
问题 I am trying to animate the drawing of a UIBeizerPath (in my example a triangle) in a UIView subclass. However, the entire subview is animating instead of the shape. Is there something I am missing with the animation? - (void)drawRect:(CGRect)rect { CAShapeLayer *drawLayer = [CAShapeLayer layer]; drawLayer.frame = CGRectMake(0, 0, 100, 100); drawLayer.strokeColor = [UIColor greenColor].CGColor; drawLayer.lineWidth = 4.0; [self.layer addSublayer:drawLayer]; UIBezierPath *path = [UIBezierPath

CATransaction rotate layer 360 degree strange

孤街浪徒 提交于 2020-01-10 06:05:09
问题 I want to perform an infinite 360 degrees rotation animation, so I coded: - (void)rotate { __weak typeof(self) weakSelf = self; [CATransaction begin]; [CATransaction setDisableActions:NO]; [CATransaction setCompletionBlock:^{ [weakSelf rotate]; }]; [CATransaction setAnimationDuration:1.0]; [CATransaction setAnimationTimingFunction: [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; self.squareLayer.transform = CATransform3DRotate(self.squareLayer.transform, M_PI, 0

Smooth shape shift animation

。_饼干妹妹 提交于 2020-01-10 02:56:10
问题 How to shift shape (from oval to rect and vice versa) animated? Dirty code: UIBezierPath *roundedRectBezierPath = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:10]; UIBezierPath *ovalBezierPath = [UIBezierPath bezierPathWithOvalInRect:newRect]; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"]; animation.duration = 3; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; if (isRect) { self.shapeLayer