CoreAnimation: Bounce animation… like the Camera button

Have you seen the animation in which the lockscreen bounces… if you tap over the camera button?. Guess what!. That can be done, quite easily, with Core Animation.

We’ll implement this as an extension to UIView. So.. add a file named ‘UIView+CoreAnimation.h/m’, and paste the following code:

REF: Thanks to the Cocoanetics author for sharing this. I’ve tweaked his code just a little bit.

[cc lang=”objc”]
#import

+ (CAKeyframeAnimation*)dockBounceAnimationWithViewHeight:(CGFloat)viewHeight
{
NSUInteger const kNumFactors = 22;
CGFloat const kFactorsPerSec = 30.0f;
CGFloat const kFactorsMaxValue = 128.0f;
CGFloat factors[kNumFactors] = {0, 60, 83, 100, 114, 124, 128, 128, 124, 114, 100, 83, 60, 32, 0, 0, 18, 28, 32, 28, 18, 0};

NSMutableArray* transforms = [NSMutableArray array];

for(NSUInteger i = 0; i < kNumFactors; i++) { CGFloat positionOffset = factors[i] / kFactorsMaxValue * viewHeight; CATransform3D transform = CATransform3DMakeTranslation(0.0f, -positionOffset, 0.0f); [transforms addObject:[NSValue valueWithCATransform3D:transform]]; } CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; animation.repeatCount = 1; animation.duration = kNumFactors * 1.0f/kFactorsPerSec; animation.fillMode = kCAFillModeForwards; animation.values = transforms; animation.removedOnCompletion = YES; // final stage is equal to starting stage animation.autoreverses = NO; return animation; } - (void)jump { CGFloat midHeight = self.frame.size.height * 0.5f; CAKeyframeAnimation* animation = [[self class] dockBounceAnimationWithViewHeight:midHeight]; [self.layer addAnimation:animation forKey:@"bouncing"]; } [/cc]

OSX Lion: Refresh Launchpad Contents

I recently came across a problem. The contents of the launchpad, somehow, got corrupt. I was seeing files that shouldn’t be there. So… how did i fix it?

Open this folder:

[cc lang=”bash”]~/Library/Application Support/Dock[/cc]

(CMD + Shift + G… and paste that!). Once you’re right there… you’ll need to delete delete the “.db” file. Last step… relaunch the dock!

[cc lang=”bash”]killall Dock[/cc]

That’s it!

CoreGraphics: Drawing Dashed Lines

Suppose you wanna draw a dashed line all around a control. What should we do?. Well… simple. We need to invoke some CoreGraphics dark magic… it’s pretty self explanatory. The catch to it is that it’ll draw a dashed line. Play with it..!

[cc lang=”objc”]
static CGFloat const kDashedBorderWidth = (2.0f);
static CGFloat const kDashedPhase = (0.0f);
static CGFloat const kDashedLinesLength[] = {4.0f, 2.0f};
static size_t const kDashedCount = (2.0f);

– (void)drawRect:(CGRect)rect
{
[super drawRect:rect];

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, kDashedBorderWidth);
CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor);

CGContextSetLineDash(context, kDashedPhase, kDashedLinesLength, kDashedCount) ;

CGContextAddRect(context, rect);
CGContextStrokePath(context);
}
[/cc]

Old School Mac

So… we’re stuck in 2012. While technology moves forward in a fast pace, the human aspect of our society gets worse as well. If you think about it … it’s wicked. We have all of this cool tech, yet, people die of hunger all over the world.

Not too long ago… everyone thought that tech would change the world. Say.. back in 1984.

Guess what!. If you miss that epoch… and don’t feel ashamed about it, you can skin your OSX to make it look as the ooooold Mac System. It’s pretty cool, and you can get it for free right here.

%d