views:

25

answers:

2

Hi all,

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

A: 

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.frame or self.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.

mvds
That was it. Thanks a bunch! After looking at it a bit more, I do agree that [UIView beginAnimations...] is probably the best way to do it.
Brett
A: 

You've made the view appear to be in a different place, but because you haven't actually changed its position it is still effectively in the old location for things like hit testing, etc.

I would start by animating your view's center instead of its transform. This you can do with just a UIView animation instead of a CABasicAnimation. Additionally, your view will actually end up at the correct position when the animation is complete so things should work as you expect.

Jason Foreman