3

我想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.

4

1 回答 1

2

UIView动画不是这样做的好选择,而不是 try 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"];
}

你可以在添加UIViewas之后使用它,subView然后你可以调用这个方法来缩放它。要使用此方法推出子视图,您需要removeFromSubView在动画完成后使用。因为知道它什么时候用完

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

我希望它有用!

于 2012-07-01T08:40:59.830 回答