【问题标题】:xcode masonry doesn't set the correct framexcode masonry 没有设置正确的框架
【发布时间】:2015-07-09 23:12:41
【问题描述】:

我在一个使用砌体自动布局的项目中,我在动画方面遇到了一些问题,所以我要做的就是让一个抽屉从屏幕顶部出现并出现带有动画,因此容器视图的内容(可以是 1 个视图或多个视图)是使用带有砖石的视图添加的,我遇到的问题是,当我调试视图时,我得到的框架始终是 Frame (0 0; 0 0) y 因为我需要应用动画我需要框架来捕获容器视图的高度,有没有办法拥有正确的框架,或者它是处理动画和自动布局的特定方式?

【问题讨论】:

    标签: ios objective-c xcode animation masonry-ios-osx


    【解决方案1】:

    尝试在viewDidLayoutSubviews 中为UIViewControllerlayoutSubviews 中为UIView 捕获框架的高度。

    要为AutoLayout 应用动画,您必须像这样重置约束:

    // tell constraints they need updating
    [self setNeedsUpdateConstraints];
    
    // update constraints now so we can animate the change
    [self updateConstraintsIfNeeded];
    
    [UIView animateWithDuration:0.4 animations:^{
        [self layoutIfNeeded];
    }];
    

    并更新或重新制作updateConstraints 中的约束。

    另请参阅:https://github.com/SnapKit/Masonry/blob/master/Examples/Masonry%20iOS%20Examples/MASExampleUpdateView.m

    【讨论】:

    • 非常感谢,它真的帮了我很大的忙。
    猜你喜欢
    • 2016-03-24
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 2013-12-14
    • 2012-02-26
    相关资源
    最近更新 更多