当父UIView动画时,UILabel大小突然改变

时间:2012-06-10 07:39:05

标签: objective-c animation uiview size uilabel

我想用动画发送超级UIView的子视图,它运行正常但是当我试图在动画期间改变大小时,我在子视图中的任何UILabel突然变得太小。 这是我的代码的一部分

-(void)pushOutScreen:(UIViewController *)pop{
    [UIView animateWithDuration:1
                      delay:0.0
                    options: UIViewAnimationTransitionFlipFromLeft
                 animations:^{

                     CGRect frame = pop.view.frame;
                     frame.size.height = frame.size.height /4;
                     frame.size.width = frame.size.width /4;
                     frame.origin.x = -500;
                     frame.origin.y = 318;

                     pop.view.frame = frame;
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];
}   

注意:我的子视图中的任何UIButtonUIImage动画都很好,但我只对UILabel有疑问。

1 个答案:

答案 0 :(得分:2)

UIView动画不适合这样做,而不是尝试CAKeyframeAnimation。这是用于缩放UIView的示例代码:

- (void) scaleView:(UIView *)popView {
    CAKeyframeAnimation *animation = [CAKeyframeAnimation
                                  animationWithKeyPath:@"transform"];
    animation.delegate = self;

    // CATransform3DMakeScale has 3 parameter (x,y,z)
    CATransform3D scale1 = CATransform3DMakeScale(1.0, 1.0, 1);
    CATransform3D scale2 = CATransform3DMakeScale(0.2, 0.2, 1);

    NSArray *frameValues = [NSArray arrayWithObjects:
                        [NSValue valueWithCATransform3D:scale1],
                        [NSValue valueWithCATransform3D:scale2],
                        nil];
    [animation setValues:frameValues];

    NSArray *frameTimes = [NSArray arrayWithObjects:
                       [NSNumber numberWithFloat:0.0],
                       [NSNumber numberWithFloat:1.0],
                       nil];    
    [animation setKeyTimes:frameTimes];

    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.duration = 1.0;

    [popView.layer addAnimation:animation forKey:@"popup"];
}

您可以在将UIView添加为subView后使用此功能,然后您可以将此方法称为缩放比例。要使用此方法推出子视图,您需要在动画结束后使用removeFromSubView。 知道什么时候完成使用

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    [subView removeFromSuperview];
}

我希望它有用!