Ios iPhone Cabasicanization-transform.scale之后设置的新边界在哪里

Ios iPhone Cabasicanization-transform.scale之后设置的新边界在哪里,ios,objective-c,iphone,core-animation,Ios,Objective C,Iphone,Core Animation,我正在使用下面的代码转储我正在设置动画的视图的层和表示层的前后边界状态。我没有看到任何变化——就我的理解而言,我似乎遗漏了一些东西——我已经阅读了几遍CA编程指南,但都没有用。任何指导都将不胜感激 -(空)收缩{ [Dumper dumpRect:@“在层边界之前”:[iv.层边界]; [Dumper dumpRect:@“在p层边界之前”:[iv.layer.presentationLayer边界] [UIView animateWithDuration:1.5 animations:^{

我正在使用下面的代码转储我正在设置动画的视图的层和表示层的前后边界状态。我没有看到任何变化——就我的理解而言,我似乎遗漏了一些东西——我已经阅读了几遍CA编程指南,但都没有用。任何指导都将不胜感激


-(空)收缩{
[Dumper dumpRect:@“在层边界之前”:[iv.层边界];
[Dumper dumpRect:@“在p层边界之前”:[iv.layer.presentationLayer边界]

[UIView animateWithDuration:1.5 animations:^{
      CABasicAnimation *scaleAnim = [CABasicAnimatianimationWithKeyPath:@"transform.scale"];

        scaleAnim.fromValue = [NSNumber numberWithFloat:1];
        scaleAnim.toValue = [NSNumber numberWithFloat:0.5];

    scaleAnim.autoreverses=NO;
    [scaleAnim setDuration:1];
    // these need to be invoked to retain the scaled version
    scaleAnim.removedOnCompletion = NO;
    [scaleAnim setFillMode:kCAFillModeForwards];

    [iv.layer addAnimation:scaleAnim forKey:@"scale"];

}completion:^(BOOL finished){

    NSLog(@"Animation done - %d",finished);
    [Dumper dumpRect:@"AFTER layer bounds" :[iv.layer bounds]];
    [Dumper dumpRect:@"AFTER p-layer bounds" :[iv.layer.presentationLayer bounds]];

}];
}

运行此代码时,我得到以下信息: 层边界前-矩形x=0.000000 y=0.000000 w=100.000000 h=200.000000 p层边界前-矩形x=0.000000 y=0.000000 w=100.000000 h=200.000000 动画完成-1 层边界后-矩形x=0.000000 y=0.000000 w=100.000000 h=200.000000 p层边界后-矩形x=0.000000 y=0.000000 w=100.000000 h=200.000000

所以前后没有变化

即使是“transform.translation”转换,我也观察到了同样的行为

我需要最终的边界,以便我可以设置UIView,即iv,以设置适当的帧值


相关的问题是-我知道,当图层设置动画时,它只是完成了绘图,但基础视图仍然使用原始帧设置-设置UIView帧的正确方法是什么。

您不应该将该代码放在
UIView
animateWithDuration
方法中。如果只想为某个对象设置动画,可以使用
cabasicanition
;如果要实际更改某个对象并对其设置动画,可以使用
animateWithDuration
。例如,如果要更改动画帧,请编写:

[UIView animateWithDuration:1.5 animations:^{
    CGRect newFrame = CGRectMake(0, 0, 50, 100);
    iv.frame = newFrame;
}completion:^(BOOL finished){
    // Code to be executed after the animation
}];

这将更改您的帧,并设置动画。希望这有帮助

感谢您的回复-您提供的代码工作得非常好。我还想试试卡巴斯基化。我在下面用CABasicAnimation编写的代码确实为视图设置了动画,但与之前一样,图层的最终帧值保持不变……因此动画是作为动画的一部分绘制的,但图层(&presentation layer)值不反映它?请引导。。。TIAOk-终于发现了问题(感觉像在背后踢自己:-)。将“在转储调用之后”移动到委托方法,瞧,p层具有正确的帧值。-(void)animationDidStop:(CABasicAnimation*)动画完成:(BOOL)标志{NSLog(@“animationDidStop”);[Dumper-dumpRect:@“在层帧之后”:[iv.layer-frame]];[Dumper-dumpRect:@“在层帧之后”:[iv.layer.presentationLayer-frame];[Dumper-Dumper-dumpRect:@“在层帧之后”:iv.layer.frame];}