UIView的Frame属性未在iOS中的动画内部分配

时间:2014-03-04 19:18:32

标签: ios uiview uianimation

在我的iOS应用程序中,我正在尝试执行以下简单动画:

- (void)dismissToolbar
{


    NSLog(@"bx: %f by: %f bw: %f bh: %f ",
            toolbar.frame.origin.x,
            toolbar.frame.origin.y,
            toolbar.frame.size.width,
            toolbar.frame.size.height);

    CGRect tempRect = CGRectMake(0,
                                 toolbar.frame.origin.y + toolbar.frame.size.height,
                                 toolbar.frame.size.width,
                                 toolbar.frame.size.height);

    [UIView animateWithDuration:animationsDuration
                          delay:0
                        options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowAnimatedContent
                     animations:^{
                         NSLog(@"bx: %f by: %f bw: %f bh: %f ",
                               tempRect.origin.x,
                               tempRect.origin.y,
                               tempRect.size.width,
                               tempRect.size.height);
                         toolbar.frame = tempRect;   // frame value doesn't change here!
                     }
                     completion:^(BOOL finished) {

                         NSLog(@"bx: %f by: %f bw: %f bh: %f ",
                               toolbar.frame.origin.x,
                               toolbar.frame.origin.y,
                               toolbar.frame.size.width,
                               toolbar.frame.size.height);
                         NSLog(@"dismiss toolbar complete");
                         [toolbar setHidden:YES];
                         isPlayerToolbarActive = NO;
                         isDissmissingToolbar = NO;
                     }
     ];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"animateSidePanels" object:@"removingPlayerToolbar"];
}

我从上面的日志中获得以下输出到控制台:

bx:0.000000 by:724.000000 bw:1024.000000 bh:44.000000

bx:0.000000 by:768.000000 bw:1024.000000 bh:44.000000

bx:0.000000 by:724.000000 bw:1024.000000 bh:44.000000

关闭工具栏完成

你可以看到框架的价值没有改变......我真的不明白为什么......

任何形式的帮助都非常感谢!

1 个答案:

答案 0 :(得分:2)

您是否使用xib或界面生成器创建了视图?

如果是这样,请尝试选择xib并取消选择使用autoLayout

enter image description here