简体   繁体   中英

Animation of UIButton decreases its size

Here is a small clip of a view being animated by me:

Animation flash

在此处输入图片说明

I am having problems when animation from ? to S and vice versa. I am setting the appropriate frames to go off screen, and then back on from the other size. Why does the size of the black button decrease with every move around it?

-(void)moveToRight
{
//just made this method up, but my actual code
//special case
if (currentDay == 7) {
    //move off the screen to the right
    CGRect offScreenRightFrame = CGRectMake(self.circle.frame.origin.x + 60, self.circle.frame.origin.y, self.circle.frame.size.width, self.circle.frame.size.height);
    //move to the left of the screen so we can animate it in
    CGRect offScreenLeftFrame = CGRectMake(-40, self.circle.frame.origin.y, self.circle.frame.size.width, self.circle.frame.size.height);

    if (self.delegate) {
        if ([self.delegate respondsToSelector:@selector(dayChangedTo:)]) [self.delegate dayChangedTo:[self getCurrentDay]];
    }

    [self pulseCircle];
    [UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
        self.circle.frame = offScreenRightFrame;
    }completion:^(BOOL finished) {
        if (finished) {
            self.circle.alpha = 0.0f;
            self.circle.frame = offScreenLeftFrame;
            [UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
                self.circle.center = self.labelSun.center;
                self.circle.alpha = 1.0f;
            }completion:^(BOOL finished) {
                if (finished) {
                    [UIView animateWithDuration:0.25f animations:^{
                        [self changeColors];
                        [self pulseCircle];
                    }];
                }
            }];
        }
    }];
}

-(void)moveLeft
{
if (currentDay == 8) {

    CGRect circleFrame = self.circle.frame;

    CGRect offScreenLeft = CGRectOffset(circleFrame, -20, 0);
    CGRect offScreenRightFrame = CGRectMake(self.labelQuestion.frame.origin.x + 30, self.labelQuestion.frame.origin.y, circleFrame.size.width, circleFrame.size.height);

    [self pulseCircle];
    [UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
        self.circle.frame = frame;
    }completion:^(BOOL finished) {
        if (finished) {
            self.circle.alpha = 0.0f;
            self.circle.frame = frameFinal;
            [UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
                self.circle.center = self.labelQuestion.center;
                self.circle.alpha = 1.0f;
            }completion:^(BOOL finished) {
                if (finished) {
                    [UIView animateWithDuration:0.25f animations:^{
                        [self changeColors];
                        [self pulseCircle];
                    }];
                }
            }];
        }
    }];
}


- (void)pulseCircle 
{ 
__block UILabel *day = [self getLabelOfDay];
[UIView animateWithDuration:TRANLATE_DURATION/2 delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    self.circle.layer.transform = CATransform3DMakeScale(1.35f, 1.35f, 1);
    day.transform = CGAffineTransformMakeScale(1.35f, 1.35f);
}completion:^(BOOL finished) {
        [UIView animateWithDuration:TRANLATE_DURATION/2 animations:^{
            self.circle.layer.transform = CATransform3DIdentity;
            day.transform = CGAffineTransformIdentity;
        }];
}];
}

I just put my logic.. honestly i don't read/see your code/logic but may be my idea work for you ;) So, I think.. you should add size of circle in public variable as default size. And set this size whenever you rich at.

if (currentDay == 0 || currentDay == 8)
{
   // Here you need to set your default size.
}

May be my logic work for you, Because 1 to 7 day its work fine but issue created at when currentDay rich at 0 or 8 day.

Thanks :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM