Fixing ‘Text in UITextField moves up after editing’ glitch

I’ve recently come across this glitch in iOS: Text in UITextField moves up after editing (center while editing).

Long short story… when you end editing a textField, if you’re using a custom font, the text might move up. (If you get this glitch). Well, it turns out that this is a font specific problem… it’s not in your code.

So… how will we solve it?. TTX!. In this previous post we explained how to make TTX work in your 64 bit mac. So we’ll begin from there.

Decompile your font. (ttx font.otx will do the trick).
Find the <hhead> section
Find the <lineGap> attribute, and set it to 0.
Recompile your font. (ttx font.ttx should work).

Try it. If that doesn’t work, you can try changing the ‘ascent’ attribute to 940, and ‘descent’ attribute to -260, which are the values that MuseoFont has.

That worked for me…!

resignFirstResponder, the easy way!

If you have an UIControl in edit mode… but you have no idea which one is it… and you need to resignFirstResponder, there is an easy way to do this. No, you don’t need to hook to notifications. And you don’t need to find the firstResponder. This can be solved with just one call.

What you need to do is…

[_tableView endEditing:YES]

Note that you could have anything else rather than a _tableView.
Easy. Right?

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.

#import <QuartzCore/QuartzCore.h>

+ (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"];
}

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:

~/Library/Application Support/Dock

(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!

killall Dock

That’s it!