calimarkus/JDFlipNumberView

change animation direction when the number get down or up

nagabarc opened this issue · 1 comments

I try to change animation direction to up when the number decreased. i hope its useful
in "- (void) animateIntoCurrentDirectionWithDuration: (CGFloat) duration
" changed
if (mCurrentDirection == eFlipDirectionDown) {
// exchange images & setup animation
if (mCurrentState == eFlipStateFirstHalf)
{
// setup first animation half
mImageViewFlip.frame = CGRectMake(0, self.frame.size.height/2.0, self.frame.size.width, self.frame.size.height/2.0);
mImageViewFlip.image = [mBottomImages objectAtIndex: mCurrentValue];
mImageViewBottom.image = [mBottomImages objectAtIndex: nextIndex];
mImageViewTop.image = [mTopImages objectAtIndex: mCurrentValue];

        // inform delegate
        if ([delegate respondsToSelector: @selector(flipNumberView:willChangeToValue:)]) {
            [delegate flipNumberView: self willChangeToValue: nextIndex];
        }

        animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 1, 0, 0)];
        animation.toValue   = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 1, 0, 0)];
        animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
    }
    else
    {
        // setup second animation half
        mImageViewFlip.image = [mTopImages objectAtIndex: nextIndex];
        animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-M_PI_2, 1, 0, 0)];
        animation.toValue   = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 1, 0, 0)];
        animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn];

    }
}else{
    // exchange images & setup animation
    if (mCurrentState == eFlipStateFirstHalf)
    {
        // setup first animation half
        mImageViewFlip.frame   = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height/2.0);
        mImageViewFlip.image   = [mTopImages    objectAtIndex: mCurrentValue];
        mImageViewBottom.image = [mBottomImages objectAtIndex: mCurrentValue];
        mImageViewTop.image    = [mTopImages    objectAtIndex: nextIndex];

        // inform delegate
        if ([delegate respondsToSelector: @selector(flipNumberView:willChangeToValue:)]) {
            [delegate flipNumberView: self willChangeToValue: nextIndex];
        }

        animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 1, 0, 0)];
        animation.toValue   = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-M_PI_2, 1, 0, 0)];
        animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn];
    }
    else
    {
        // setup second animation half
        mImageViewFlip.image = [mBottomImages objectAtIndex: nextIndex];

        animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 1, 0, 0)];
        animation.toValue   = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0, 1, 0, 0)];
        animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
    }
}

in "- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
" changed
// update images
if (mCurrentDirection == eFlipDirectionDown) {
mImageViewTop.image = [mTopImages objectAtIndex: mCurrentValue];
}else{
mImageViewBottom.image = [mBottomImages objectAtIndex: mCurrentValue];
}

in "- (void) updateFlipViewFrame
" changed
if (mCurrentDirection == eFlipDirectionDown) {
if (mCurrentState == eFlipStateFirstHalf)
{
mImageViewFlip.layer.anchorPoint = CGPointMake(0.5, 0.0);
mImageViewFlip.frame = mImageViewBottom.frame;
}
else
{
mImageViewFlip.layer.anchorPoint = CGPointMake(0.5, 1.0);
mImageViewFlip.frame = mImageViewTop.frame;
}
}else{
if (mCurrentState == eFlipStateFirstHalf)
{
mImageViewFlip.layer.anchorPoint = CGPointMake(0.5, 1.0);
mImageViewFlip.frame = mImageViewTop.frame;
}
else
{
mImageViewFlip.layer.anchorPoint = CGPointMake(0.5, 0.0);
mImageViewFlip.frame = mImageViewBottom.frame;
}
}

v2 determines the direction automatically (currently on develop branch)