【问题标题】:Unable to be change view's frame after adding topLayoutGuide添加 topLayoutGuide 后无法更改视图的框架
【发布时间】:2013-12-09 02:02:58
【问题描述】:

我在导航控制器视图的超级视图中添加了一个topLayoutGuide约束,然后当我尝试更改导航控制器视图的框架时,例如:从(0,0,320,568)的当前框架到(200, 0, 320, 568) 使用

[[navigationController view] setFrame:CGRectMake(200, 0, 320, 568)];

动画结束后自动设置为 (0, 0, 320, 568)。

topLayoutGuide 约束是由这段代码添加的:

- (void)viewDidLoad { // of subclassed UINavigationController class .m file
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
        [[self view] setTranslatesAutoresizingMaskIntoConstraints:NO];

        id topGuide = [self topLayoutGuide];
        UIView * selfView = [self view];
        NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (selfView, topGuide);
        [[[self view] superview] addConstraints:
         [NSLayoutConstraint constraintsWithVisualFormat:@"V:[topGuide]-0-[selfView]"
                                             options:0
                                             metrics:nil
                                               views:viewsDictionary]];
        [[[self view] superview] layoutSubviews]; // Must call this method here or the system raises an exception
    }
}

【问题讨论】:

    标签: ios autolayout


    【解决方案1】:

    Autolayout 力求满足所有约束条件。在您的动画之后,此约束被破坏,并且在下一个布局周期中,它将满足您的约束并改回帧。 考虑动画布局约束更改或关闭自动布局。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    • 2015-12-30
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    相关资源
    最近更新 更多