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

标签 objective-c animation uiview size uilabel

我想从我的 super UIView 中发送一个带动画的 subview ,它工作正常但是当我试图在动画期间更改大小时我在任何 UILabel我的 subview 突然变得太小了。 这是我的部分代码

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

注意:我的 subview 中的任何 UIButtonUIImage 动画都很好,但我只有 UILabel 有问题。

最佳答案

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 之后使用它,然后您可以调用此方法来缩放它。要使用此方法推出 subview ,您需要在动画完成后使用 removeFromSubView。 因为知道当它完成使用时

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

希望有用!

关于objective-c - 当父 UIView 动画时,UILabel 大小突然改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967067/

相关文章:

ios - 如何将 UIImage 正确地锚定到位于自定义单元格中的 UIView 中?

iphone - 自定义 UIView 和 UIViewController 最佳实践?

iphone - 将 NSDictionary 转换为可变

c++ - 如何在 SFML 中为 Sprite 制作动画

jquery - 显示:none stopping initial translate3d animation

ios - 如何启用在模态视图上使用双指 UIAccessibility "escape"手势的能力?

objective-c - iCloud、Core Data 和 Xcode 6.01 与 iOS 8 的无效代码签名授权

python - Python 的 os.system() 相当于 cocoa/Objective-C 的什么?

iphone - 如何将 NSDictionary 转换为 NSMutableDictionary?

html - 在没有 Canvas 元素的情况下在 HTML 中裁剪 DIV