core-animation

Animate CAShapeLayer path change

懵懂的女人 提交于 2019-12-01 05:17:03
I'm trying to animate change of path property of CAShapeLayer like this: animatePathChange(for: progressLayer, toPath: progressPath.cgPath) progressLayer.path = progressPath.cgPath And this is animatePathChange function code: func animatePathChange(for layer: CAShapeLayer, toPath: CGPath) { let animation = CABasicAnimation(keyPath: "path") animation.duration = 1.0 animation.fromValue = layer.path animation.toValue = toPath animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut") layer.add(animation, forKey: "path") } But the end result is not what i want. How can i achieve

Animate a layer property which simply changes other properties?

心已入冬 提交于 2019-12-01 04:58:46
Imagine a CAGradientLayer . It's very easy to animate .startPoint and .endPoint . Now imagine a float spinLike which simply sets both of them at once . {So, instead of having two different animations, you could simply animate spinLike .} So something like .. class CustomGradientLayer: CAGradientLayer { @objc var spinLike: CGFloat = 0 { didSet { startPoint = CGPoint( ... ) endPoint = CGPoint( ... ) setNeedsDisplay() } } } To animate spinLike ... class Test: UIView { ... g = CustomGradientLayer() a = CABasicAnimation(keyPath: "spinLike") ... g.add(a, forKey: nil) ... But. It doesn't work,

Swift - Color fill animation

守給你的承諾、 提交于 2019-12-01 04:29:27
I'm relatively new to ios animations and I believe there's something wrong with the approach I took to animate UIView. I will start with a UI screenshot to picture my problem more precisely: There is a tableView cell with two labels and colorful filled circle Anytime I introduce new value to the cell, I'd like to animate this left-most bulb so it looks like it's getting filled with red color. This is the implementation od BadgeView, which is basically the aforementioned leftmost filled circle class BadgeView: UIView { var coeff:CGFloat = 0.5 override func drawRect(rect: CGRect) { let topRect

Why is -animateWithDuration:delay:options:animations:completion: blocking the UI?

心已入冬 提交于 2019-12-01 04:09:46
I always thought that Core Animation performs animations on the background. When I run this code, my UI interactions are blocked until the animation finishes: [UIView animateWithDuration:4.5 delay:0 options:options animations:^{ oldView.alpha = 0; newView.alpha = 1; } completion:^(BOOL finished) { if (finished) { [oldView removeFromSuperview]; } }]; Like you can see the duration is long so it's clearly visible that the UI interactions are blocked while animating. The UI interaction begins to be blocked when the animation begins, and ends to be blocked when the animation finishes. Is there a

Can a single CALayer be used as the mask for multiple other layers?

拥有回忆 提交于 2019-12-01 04:05:10
问题 I can't find anything in the docs that indicates whether a single CALayer (or subclass) can be used as the mask property for multiple other layers. Is it possible? Or undefined? 回答1: My experimentation says that it cannot. It will end up as the mask for the last layer it is attached to, and any previous layers it was assigned as a mask to, will revert to the default value of mask. 回答2: It is possible. I combined mask of CAGradationLayer and CAShapeLayer. I made UIImage from two layers, and I

Revolving animation, that follows finger, of uibuttons that follows outer path of circle

北城余情 提交于 2019-12-01 03:48:35
问题 I am looking for a little guidance to start figuring out an animation that tracks finger movement and moves a collection of UIButtons along the outer path of a circle I am picturing it will kind of have a revolver feel to it. Like each one locks into place at the bottom or like the swiping through one of the slide inserts of these thanks in advance 回答1: (Sample code on GitHub) It's not really that difficult, there's just a lot of trigonometry involved. Now, what I'm going to describe now, is

how can I detect the completion of an animation triggered by CATransaction

岁酱吖の 提交于 2019-12-01 03:43:48
问题 I have a CALayer which I merely create and add to a subview of my view controller's main view in the controller's initWithNibName: And then, I perform the following animation: [CATransaction begin]; [CATransaction setAnimationDuration:2]; [logoLayer setOpacity:0]; [CATransaction commit]; How can I tell when this animation is done? the performSelector: delayed by 2 secs. approach doesn't seem "the right way" to go about it. 回答1: According to the doc, [CATransaction setCompletionBlock:] could

How to facebook style transition

ε祈祈猫儿з 提交于 2019-12-01 03:17:22
问题 Want to implement a view controller transition similar to used in facebook and many other apps, snapshot is attached. Will it require playing with CoreAnimation framework or is it available in the toolkit? 回答1: You have to use CoreAnimation unless you want to import a 3rd part framework that someone suggested, but it is very simple to use CoreAnimation and I suggest you learn it because it is very powerful. Here is the simplest approach possible to give you an idea. You could structure it a

How difficult to creat a simple eraser effect on core animation or core graphic?

扶醉桌前 提交于 2019-12-01 02:24:09
Hi i will like to create an eraser animation or core graphic that looks like rubbing away the current content and add in a new content on a uibutton when i tapped on the view or button. is it tough to do it ?, any tutorial or web link to show how to do it ? Dhanesh Hi, we can use this eraser functionality with core animation in our app like below: CGPoint currentPoint = [touch locationInView:imgBlankView]; UIGraphicsBeginImageContext(self.view.frame.size); [imgBlankView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, imgBlankView.frame.size.height)]; CGContextSetLineCap

How to use CoreAnimation to animate a circle like a clock countdown

旧巷老猫 提交于 2019-12-01 01:21:34
I wish to have a time countdown indicator just like a circle to start from a slice of arch to a full circle. I have tried several ways, both ended up with the arch turning directly to be a full circle, not go clockwise. Shown in demo pics as following: Any idea? Greatly appreciated! SetNeedsDisplay when you change one of the angles, you can do some optimizations to only redraw the affected area. Put something like this into your draw function of your view. Good Luck CGContextRef myContext = UIGraphicsGetCurrentContext(); CGPoint center = { self.bounds.size.width * 0.5f, self.bounds.size.height