【问题标题】:Adding a subview to view changes other subviews' frames添加子视图以查看更改其他子视图的框架
【发布时间】:2014-05-05 07:39:08
【问题描述】:

一个uiviewcontroller在stroyboard ib中添加了两个UIViews和一个tableview并与IBoutlet连接

当用户在顶部 uiview 中单击滑动时,我调用以下方法来更改所有子视图 IBoutlet 元素的框架。这行得通。

-(void)hideTopViews
{
    [UIView animateWithDuration:0.25 animations:^{
        [_overallHealth setHidden:YES];
        _overallHealth.frame =  CGRectMake(0, 0,self.view.frame.size.width,0);
        [_healthBar setHidden:YES];
        _sortView.frame =  CGRectMake(0, 45,self.view.frame.size.width,_sortView.frame.size.height);
        _portfoList.frame =  CGRectMake(0, _sortView.frame.origin.x+_sortView.bounds.size.height+50,self.view.frame.size.width,self.view.frame.size.height);
        _sortButton.frame =  CGRectMake(90, 45,_sortButton.frame.size.width,_sortButton.frame.size.height);
        [self.view bringSubviewToFront:_sortButton];
        self.navigationItem.leftBarButtonItems=nil;
    }];


}

但是,当我以编程方式将另一个子视图添加到 self.view 时,所有子视图都会返回到它们在故事板中的原始位置。

-(void)showPortfolioDetailsScreen
{
    PortfolioDetails *portView=[[PortfolioDetails alloc] initWithFrame:CGRectMake(300,200,200,200)];
    portView.backgroundColor=[UIColor redColor];
    [self.view addSubview:portView];

}

我该如何解决这个问题?

【问题讨论】:

    标签: ios objective-c ios7 uiview addsubview


    【解决方案1】:

    @tanzolone 走在正确的轨道上,如果您只使用纵向模式并希望您的故事板停止将您的子视图更改为原始帧,请转到您的故事板并取消选中 Use Autolayout

    因此您可以使用旧的支柱和弹簧模型。

    这里是自动布局的详细教程 http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2

    【讨论】:

    • 如何在不删除自动布局的情况下解决此问题?可以吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多