隐藏查看和重新定位等查看与自动版式 [英] Hide View and reposition other View with Autolayouts

查看:132
本文介绍了隐藏查看和重新定位等查看与自动版式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,球员,

我有一个包含多个信息纵断面图。他们中的一些没有被例如设定传记。所以,这取决于如果它的盘,我想隐藏的传记视图(结帐截图)和重新定位的UserData视图和ActivityData查看和更改自己的SuperView的大小以填补传记查看所做的空间。

I have a profile view that contains several informations. Some of them don't have to be set e.g. Biografie. So depending if its set, I would like to hide the Biografie View (checkout screenshot) and reposition the UserData View and the ActivityData View AND change the Size of their superview to fill the space made by the Biografie View.

下面是我的我的TableViewHeader的实际结构:

Here is my actual structure of my TableViewHeader:

另外一点,我要关心的是,该的UILabel必须mutliline和适合其内容。

The other point that i have to care about is that, the UILabel have to be mutliline and fit its content.

所以我的问题:


  • 如何重新定位的UserData&放大器; ActivityData查看填补
    由隐藏BiografieView做出空间?

  • 如何让传记
    查看高度契合UILabels文字?

请记住,我使用自动布局。所以,我必须使用约束修改的位置吧?

Please keep in mind that I'm using Autolayout. So I have to use constraints to modify the positions right?

说实话..基本上它应该是这样的Instagram,增加了传记的时候。我希望我做到了我想清楚什么..

To be honest.. Basically it should be like Instagram, when adding a Biografie. I hope I made it clear what I want..

修改1

我想你的建议达明,但没有什么正在发生变化:

I have tried your suggestion Damien, but nothing is changing:

    NSLog(@"Height %f, Width %f", self.labelBiografie.frame.size.height, self.labelBiografie.frame.size.width);

if ([self.profileUser objectForKey:kGSUserBiografieKey]) {
    self.labelBiografie.text = [self.profileUser objectForKey:kGSUserBiografieKey];
    [self.labelBiografie sizeToFit];
}else{
    [self.labelBiografie setHidden:YES];
    [self.countContainer setConstraintConstant:-self.labelBiografie.frame.size.height forAttribute:NSLayoutAttributeCenterY];
    [self.tableHeaderViewChildVIew setConstraintConstant:-self.labelBiografie.frame.size.height forAttribute:NSLayoutAttributeHeight];
    self.tableView.tableHeaderView = self.tableHeaderViewChildVIew;
}

编辑2:

使用这个项目(的UIView,UpdateAutoLayoutConstraints
)我得到的方法,以下错误:

Using this Project (UIView-UpdateAutoLayoutConstraints ) I'm getting following error on the methods:

56号线: [自hideView:隐藏byAttribute:NSLayoutAttributeHeight];

85号线: [自setConstraintConstant:0 forAttribute:属性];

23号线:

[self.superview addConstraint: [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:constant]];

ERROR:

    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x8c1b8e0 V:|-(0)-[UIButton:0x8c6fb40]   (Names: '|':UIView:0x8c6f630 )>",
    "<NSLayoutConstraint:0x8c19dc0 V:[UIButton:0x8c6fb40(100)]>",
    "<NSLayoutConstraint:0x8c1d740 V:[UIButton:0x8c6fb40]-(NSSpace(8))-[UILabel:0x8c70900]>",
    "<NSLayoutConstraint:0x8c20df0 V:[UILabel:0x8c70900]-(NSSpace(8))-[UIView:0x8c16a00]>",
    "<NSLayoutConstraint:0x8c20fa0 V:[UIView:0x8c16a00(40)]>",
    "<NSLayoutConstraint:0x8c23790 V:[UIView:0x8c16a00]-(0)-|   (Names: '|':UIView:0x8c6f630 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x8c78e60 h=--& v=--& V:[UIView:0x8c6f630(217)]>",
    "<NSLayoutConstraint:0x8c5d000 V:[UILabel:0x8c70900(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x8c20df0 V:[UILabel:0x8c70900]-(NSSpace(8))-[UIView:0x8c16a00]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

此错误表明了对示范项目开箱,我的项目时,我隐藏的观点也得到恢复。

This error shows up on the Demo-Project out of the box, on my on Project it also get returned when i hide the view..

推荐答案

我建了一个类别来回答这个问题,我也已经遇到过:
<一href=\"http://stackoverflow.com/questions/22384927/hide-autolayout-uiview-how-to-get-existing-nslayoutconstraint-to-update-this-o/22386906#22386906\">Hide自动版式的UIView:如何让现有的NSLayoutConstraint来更新这个

I built a category to answer to this problem I also already encountered : Hide autolayout uiview : How to get existing NSLayoutConstraint to update this one

编辑:

如果您使用自动布局,不要使用 view.frame 任何更多的,不要忘记设置你的自动版式视图是这样的:

If you use autolayout, do not use view.frame any more and don't forget to set all you autolayout view like this:

myView.translatesAutoresizingMaskIntoConstraints = NO;

使用这一类 https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints

if(!user.biografie && user.biografie.lenght == 0)
{
     [biografieLabel setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight];
}else
{
     biografieLabel.text = user.biografie;
}

这篇关于隐藏查看和重新定位等查看与自动版式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆