agens-no/AGGeometryKit

Issue with UIButton as subview after quad animation

mgrider opened this issue · 15 comments

I have a UIView that I'm moving around with the following:

    [self.layer animateFromPresentedStateToQuadrilateral:quad
                                                 forNumberOfFrames:duration * 60
                                                          duration:duration
                                                             delay:0.0
                                                           animKey:@"demo"
                                                      easeFunction:interpolationFunction
                                                        onComplete:onComplete];

(Code mostly stolen from the sample project.)

Anyway, the UIView contains a UIButton, and the button essentially does not receive touches after the quad animation. I've tried a couple of things in the onComplete, and verified that the button is still enabled, but using the following workaround for now:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInView:self.view];
    if ([self.gameMenuButton.layer.presentationLayer hitTest:touchLocation])
    {
        [self gameMenuButtonPressed:nil];
    }
}

Could you try to update the code of the mentioned method with this?

- (void)animateFromQuadrilateral:(AGQuad)quad1
                 toQuadrilateral:(AGQuad)quad2
               forNumberOfFrames:(NSUInteger)numberOfFrames
                        duration:(NSTimeInterval)duration
                           delay:(NSTimeInterval)delay
                         animKey:(NSString *)animKey
                    easeFunction:(double(^)(double p))progressFunction
                      onComplete:(void(^)(BOOL finished))onComplete
{
    if(!CGPointEqualToPoint(self.anchorPoint, CGPointZero))
    {
        [NSException raise:NSInternalInconsistencyException format:@"Before using any quadrilaterals the layers anchorPoint property must be {0, 0}. You may use the category method -[CALayer ensureAnchorPointIsSetToZero]"];
    }

    [CATransaction begin];

    __weak __typeof__(self) wself = self;

    void (^after)(BOOL finished) = ^(BOOL finished) {
        if(finished)
        {
            [wself removeAnimationForKey:animKey];
            wself.quadrilateral = quad2;
        }
        onComplete(finished);
    };

    CAKeyframeAnimation *anim = [[self class] animationBetweenQuadrilateral:quad1
                                                           andQuadrilateral:quad2
                                                                       rect:self.bounds
                                                          forNumberOfFrames:numberOfFrames
                                                                      delay:delay
                                                                   duration:duration
                                                               easeFunction:progressFunction
                                                                 onComplete:after];

    anim.removedOnCompletion = YES;

    [self addAnimation:anim forKey:animKey];

    [CATransaction commit];
}

I have not tested the code yet, but I think you see what I'm trying to do. Remove the animation once it is completed and set the correct value.

If installed by pod it is sufficient for testing just to change the code in the pod directly (after pod install).

Yes! This works great!

I'm getting an exception on this line, however:

        onComplete(finished);

I'm not using the completion handler (yet), so I was able to comment it out and test.

I'll see if I can fix it.

Probably just to

if(onComplete)
{
    onComplete(finished);
}

Forgot to mention that yes, that onComplete if statement works great.

Also, my initial excitement at having this work is dampened somewhat by a "flicker" that appears after the animation completes. You can see it in this video at approximately 12 or 13 seconds in: http://www.youtube.com/watch?v=dj4dIbb9Edc#t=29

I might play around with it and see if I can get a fix, but if you have any other ideas, I'd love to hear 'em. If I can't fix it, i'll probably go back to my "fake button" workaround. It's smooth as silk if I don't remove it on completion.

Thanks again!

I can see the flickering. I'll have a look!

Håvard

Sendt fra mobil

Den 18. feb. 2014 kl. 06:42 skrev Martin Grider notifications@github.com:

Forgot to mention that yes, that onComplete if statement works great.

Also, my initial excitement at having this work is dampened somewhat by a "flicker" that appears after the animation completes. You can see it in this video at approximately 12 or 13 seconds in: http://www.youtube.com/watch?v=dj4dIbb9Edc#t=29

I might play around with it and see if I can get a fix, but if you have any other ideas, I'd love to hear 'em. If I can't fix it, i'll probably go back to my "fake button" workaround. It's smooth as silk if I don't remove it on completion.

Thanks again!


Reply to this email directly or view it on GitHub.

Hi again!

First off: your game looks really fun and cute! Is it out yet?

I've commited some changes to the master branch just now. I've also tagged the latest version with 0.1.8.4.

This is the commit which is relevant for you.
76bb7ac

I'm curious about your feedback on this. If this didn't solve the problem I would be happy to skype with you in order to hunt down this bug.

Hey Thanks so much for taking the time to fix this!!! Brilliant work, it's functioning perfectly now!

The game is playable on my website (in flash). http://go-tetris.com/ I'm porting it to iOS, and adding a bunch of cool features. The iOS version is probably another month or two out, since I'm full-time on some freelance work right now, and next month looks crazy busy.

So yes and no. Hehe.

Anyway, I had to put the onComplete in an if statement on about line 162 of CALayer+AGQuad.m:

    {
        onComplete(finished);
    }

Thanks again!

Great. I'll commit that if-check later this evening (europe-time).

I'll close this issue when I've pushed those changes.

Thanks for taking interest in this framework! That's the only way I get to know what's in need of improvements and what's isn't.

I am doing a talk on gamedev in UIKit for my local Cocoaheads in early April. I'll be talking some about "juicing", and AGGeometryKit is definitely going to come up! :)

Haha. Great :D

Fixed, tagged and shipped. 0.1.8.6