I am having an issue with my UITextFields in my iPhone app that I am hoping someone here may have seen before.
I have a few UITextField’s on my screen, and when they are tapped and they keyboard appears they are covered. To overcome this, I animated the view to move up with:
-(void)moveViewUpFromValue:(float)fromOldValue toNewValue:(float)toNewValue keep:(BOOL)keep {
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
theAnimation.duration=0.25;
theAnimation.repeatCount=1;
if(keep) {
[theAnimation setRemovedOnCompletion:NO];
[theAnimation setFillMode:kCAFillModeForwards];
}
theAnimation.fromValue=[NSNumber numberWithFloat:fromOldValue];
theAnimation.toValue=[NSNumber numberWithFloat:toNewValue];
[self.view.layer addAnimation:theAnimation forKey:@"animateLayer"];
}
This, visually, works great, however, when I go to edit (hold the screen down to get the magnifying glass), it doesn’t appear. The interaction are is retained in the position before it moves.
Any ideas what could be going on here?
Many thanks,
Brett
This is an interesting way to animate such a thing, but not the most common one.
You’re actually animating a transformation of a view – not the actual position of the view. Appearantly the magnifying glass doesn’t obey the transformation (quite logical, for it would sheer, stretch and skew with the view otherwise).
So rather animate the position, i.e.
self.view.frameorself.view.center(which boils down to the same thing). Furthermore I usually use[UIView beginAnimations...]etc but if your approach works, it’s probably just as fine.