0

I am trying to animate a button. When I do so (using button.layer addAnimation) the button becomes disabled. Is there any way to allow user interaction when animating? I also tried wrapping everything in a block using animateWithDuration passing in the option UIViewAnimationOptionAllowUserInteraction, but it still doesn't work.

EDIT: It's odd. If I click in the upper corner (where I placed my button) it fires off the event. It's almost like the frame of the button does not follow the animation.

EDIT: What I ended up doing is create an event that fires every 0.1 seconds that sets the button.frame equal to the [[button.layer presentationLayer] frame]. That seemed to do the trick.

user472292
  • 1,069
  • 2
  • 22
  • 37

5 Answers5

1

the best solution is to change the position of the layer after you call the animation:

[button.layer addAnimation:animation forKey:@"animation"];

 button.layer.position = endPosition;
Mejdi Lassidi
  • 999
  • 10
  • 22
1

Use the following UIView method with UIViewAnimationOptionAllowUserInteraction in the UIViewAnimationOptions parameter:

+(void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

EricS
  • 9,650
  • 2
  • 38
  • 34
0

To me the event firing seemed a bit hacky.
However your mentioning of the [[button.layer presentationLayer] frame] brought me onto the right track :-)

So by attaching a gesture recognizer to the superview of the moving view I can do the following detection:

CGPoint tapLocation = [gestureRecognizer locationInView:self.view];

for (UIView* childView in self.view.subviews)
{
    CGRect frame = [[childView.layer presentationLayer] frame];
    if (CGRectContainsPoint(frame, tapLocation))
    {
        ....
    }
}
Jack
  • 10,943
  • 13
  • 50
  • 65
0

I wanted the button to zoom in. So I scale down the layer before I start the animation:

layer.transform = CATransform3DScale (layer.transform, 0.01, 0.01, 0.01);

// some animation code

After the animation I scaled it back.

// some animation code
CATransform3D endingScale = CATransform3DScale (layer.transform, 100, 100, 100);
// some animation code

[layer addAnimation:animation forKey:@"transform"];

layer.transform = endingScale;

Looks like if you directly assign it to the layer the frame will change. However using an animation won't change the frame.

Xazen
  • 822
  • 2
  • 12
  • 26
0

What I ended up doing is create an event that fires every 0.1 seconds that sets the button.frame equal to the button.layer

user472292
  • 1,069
  • 2
  • 22
  • 37
  • the best solution is to change the position of the layer after you call the animation: button.layer.position = endPosition; – Mejdi Lassidi Jun 20 '15 at 18:52