Frame property of UIView is not getting assigned inside animation on iOS

眉间皱痕 提交于 2019-12-02 17:12:47

问题


In my iOS app I'm trying to perform following simple animation:

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

I'm getting the following output to a console from the logs above:

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

dismiss toolbar complete

as you can see the value of the frame didn't change...and I don't really understand why...

any kind of help is highly appreciated!


回答1:


Did you create the view with xib's or interfaceBuilder?

If so, try selecting the xib and deselecting use autoLayout



来源:https://stackoverflow.com/questions/22180969/frame-property-of-uiview-is-not-getting-assigned-inside-animation-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!