How do you create a wiggle animation similar to iphone deletion animation

The answer by Vinzius is very cool. However the wobble only rotates from 0 Radians to 0.08. Thus the wobble can look a little unbalanced. If you get this same issue then you may want to add both a negative and a positive rotation by using a CAKeyframeAnimation rather than a CABasicRotation: – (CAAnimation*)getShakeAnimation { … Read more

Transforming a rectangle image into a quadrilateral using a CATransform3D

I’ve created a kit for doing this on iOS: https://github.com/hfossli/AGGeometryKit/ Make sure your anchor point is top left (CGPointZero). + (CATransform3D)rectToQuad:(CGRect)rect quadTL:(CGPoint)topLeft quadTR:(CGPoint)topRight quadBL:(CGPoint)bottomLeft quadBR:(CGPoint)bottomRight { return [self rectToQuad:rect quadTLX:topLeft.x quadTLY:topLeft.y quadTRX:topRight.x quadTRY:topRight.y quadBLX:bottomLeft.x quadBLY:bottomLeft.y quadBRX:bottomRight.x quadBRY:bottomRight.y]; } + (CATransform3D)rectToQuad:(CGRect)rect quadTLX:(CGFloat)x1a quadTLY:(CGFloat)y1a quadTRX:(CGFloat)x2a quadTRY:(CGFloat)y2a quadBLX:(CGFloat)x3a quadBLY:(CGFloat)y3a quadBRX:(CGFloat)x4a quadBRY:(CGFloat)y4a { CGFloat X = rect.origin.x; CGFloat Y … Read more

UIView.animateWithDuration swift loop animation

No need to do the completion block approach, just use the animation options argument: updated for Swift 3.0 UIView.animate(withDuration: 2.0, delay: 0, options: [.repeat, .autoreverse], animations: { coloredSquare.frame = CGRect(x: 120, y: 220, width: 100, height: 100) }, completion: nil) If for any reason you want to stop the animation later, just use: coloredSquare.layer.removeAllAnimations()

Shake visual effect on iPhone (NOT shaking the device)

I think this is a more efficient solution: Swift: let anim = CAKeyframeAnimation( keyPath:”transform” ) anim.values = [ NSValue( CATransform3D:CATransform3DMakeTranslation(-5, 0, 0 ) ), NSValue( CATransform3D:CATransform3DMakeTranslation( 5, 0, 0 ) ) ] anim.autoreverses = true anim.repeatCount = 2 anim.duration = 7/100 viewToShake.layer.addAnimation( anim, forKey:nil ) Obj-C: CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@”transform” ] ; … Read more

How to crossfade between 2 images on iPhone using Core Animation

You were almost there. CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@”contents”]; crossFade.duration = 5.0; crossFade.fromValue = image1.CGImage; crossFade.toValue = image2.CGImage; [self.imageView.layer addAnimation:crossFade forKey:@”animateContents”]; Note that the animation is independent of the actual values/contents of the UIImageView. Therefore you’ll need to self.imageView.image = image2; … to set the final result for your image.

What’s the difference between a CoreAnimation Layer Backed View and a Layer Hosting View?

A layer backed view contains Cocoa or Cocoa Touch UI controls and can be animated using the animator proxy. Layer backed views allow you to animate your UI and help to reduce the overhead of drawing by caching the views contents on a core animation layer. Create a Layer backed view by setting the wants … Read more