UIButton的动画减小了它的大小

时间:2014-01-06 08:26:19

标签: ios iphone objective-c cocoa-touch

这是我的动画视图的一个小片段:

Animation flash

enter image description here

动画来自时我遇到了问题?到S,反之亦然。我正在设置适当的帧以离开屏幕,然后从另一个大小重新开启。为什么黑色按钮的大小会随着每次移动而减小?

-(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;
        }];
}];
}

1 个答案:

答案 0 :(得分:0)

我只是把我的逻辑......老实说,我不读/看你的代码/逻辑,但可能是我的想法为你工作;) 所以,我认为..你应该在公共变量中添加圆的大小作为默认大小。每当你富裕时设置这个大小。

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

可能是我的逻辑工作,因为 1 7 天它的工作正常,但是当 currentDay 富有 0 或 8 天。

谢谢:)