Core Animation, unexpected animated position and hitTest values

泄露秘密 提交于 2019-12-04 05:41:23

问题


When I use :

CALayer *hitLayer = 
[[self.view.window.layer presentationLayer] hitTest:pointOfTouch]; 
I then explore the layer to discover that all the property that are animating at the moment are set to their final states.

The layer I'm testing on is the CALayer of an UIImageView in iOS 4.3. I also have an IBOutlet to that UIImage view. So I did the same test like this:

  CALayer *l = [self.topLeft.layer presentationLayer];
  NSLog(@"presentation layer frame for eloise is : %@", [self cgRectDescription:l.frame]);
  NSLog(@"and xPosition = %.2f, yPosition = %.2f & zPosition = %.2f", l.position.x, l.position.y, l.zPosition);
And I still get the same result.
I'm testing this in (void)touchesBegan:withEvent: while the image is moving.
Here is the animation I'm using
[UIImageView animateWithDuration:aDuration
                            delay:0
                          options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState
                       animations:^(void) {
                                  aIv.center = imageStartingPoint;
                                  aIv.layer.zPosition = 0;
                                  imageStartingPoint = CGPointZero;
                                  centerImage = nil;

                              CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"shadowOffset"];
                              ba.fromValue = [NSValue valueWithCGSize:aIv.layer.shadowOffset];
                              ba.toValue = [NSValue valueWithCGSize:CGSizeMake(0, 0)];
                              aIv.layer.shadowOffset = CGSizeMake(0, 0);
                              ba.duration = aDuration;
                              ba.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
                              [aIv.layer addAnimation:ba forKey:@"shadowOffset"];

                              ba = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];
                              ba.fromValue = [NSNumber numberWithFloat:aIv.layer.shadowRadius];
                              ba.toValue = [NSNumber numberWithFloat:0];
                              aIv.layer.shadowRadius = 0;
                              ba.duration = aDuration;
                              ba.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
                              [aIv.layer addAnimation:ba forKey:@"shadowRadius"];
                       } 
                       completion:NULL];    </pre> </code>

It's probably a little simple thing, but I'm out of idea, thanks,


回答1:


I've got a solution.

I just explored an idea, I realize that I didn't check if the value of the CABasicAnimation(s) where behaving correctly in the presentation layer... and... they were.
I had to do those 2 in explicit animation, because implicit was not supported.

So I made some more basic animation for the center of the image and the zPosition. And now I have the information in the presentation layer.

So for now I can conclude that if you need to get a valid presentation layer you absolutely need to do EXPLICIT animation with a CAAnimation.

I'm kind of sad, because I was liking the UIView animateWithDuration:...



来源:https://stackoverflow.com/questions/7962335/core-animation-unexpected-animated-position-and-hittest-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!