标签: nsautolayout

在UITableView中使用自动布局来获取动态单元格布局和可变行高

如何UITableViewCell在表格视图中使用s 内的自动布局,让每个单元格的内容和子视图确定行高(本身/自动),同时保持平滑的滚动性能?

row-height uitableview ios autolayout nsautolayout

1477
推荐指数
18
解决办法
55万
查看次数

AutoLayout,无法同时满足约束

刚开始学习iOS AutoLayout,界面构建器非常直接,但是当我尝试在代码上存档相同的东西时

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(==2)-[_nextKeyboardButton]-(==2)-[_numPadButton]-(==2)-[_spaceButton]-(==2)-[_returnButton]-(==2)-|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_nextKeyboardButton,_numPadButton,_spaceButton,_returnButton)]];
Run Code Online (Sandbox Code Playgroud)

它提出了一个例外,

无法同时满足约束.

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:0x6000000966c0 H:|-(2)-[UIButton:0x7fe4f1d1c760'Next']   (Names: '|':UIInputView:0x7fe4f1f04d00 )>", …
Run Code Online (Sandbox Code Playgroud)

objective-c ios nsautolayout

30
推荐指数
3
解决办法
3万
查看次数

NSAutoLayout标准空间值

使用AutoLayout时,您可以勾选Interface Builder中的"标准"框,或者您可以使用... @"| - [someElement] - |"直观地创建它.

是否有一个常量可以用来访问这个"标准"代表的值?

我想创建一个NSLayoutConstraintconstant属性等于这个standard值.

ios nsautolayout

17
推荐指数
1
解决办法
3140
查看次数

如何更新swift Layout Anchors?

试图找到一个解决方案来更新事件上多个UI元素的多个约束.我已经看到了一些停用,进行更改,然后重新激活约束的示例,这种方法对于我正在使用的24个锚点似乎不切实际.

我的一组变化:

ticketContainer.translatesAutoresizingMaskIntoConstraints = false
ticketContainer.topAnchor.constraintEqualToAnchor(self.topAnchor).active = true
ticketContainer.leftAnchor.constraintEqualToAnchor(self.rightAnchor, constant: 20).active = true
ticketContainer.widthAnchor.constraintEqualToConstant(200.0).active = true

ticketContainer.leftAnchor.constraintEqualToAnchor(self.leftAnchor, constant: 20).active = true
ticketContainer.widthAnchor.constraintEqualToConstant(100.0).active = true
Run Code Online (Sandbox Code Playgroud)

ios autolayout nsautolayout swift layout-anchor

15
推荐指数
2
解决办法
3万
查看次数

布局中的奇怪异常

尝试调用此方法:

avatarIconImageView.setContentHuggingPriority(UILayoutPriorityDefaultLow, forAxis: UILayoutConstraintAxis.Horizontal)
Run Code Online (Sandbox Code Playgroud)

并捕获此异常:

架构armv7的未定义符号:
"_ UILayoutPriorityDefaultLow",引用自:__ TFCvatar_iOS36TCAvatarWithCounterUniversalCellView22configureBodyCellViewsfS0_FT_T_ in TCAvatarUniversalCellView.o ld:未找到架构armv7 clang的符号:错误:链接器命令失败,退出代码为1(使用-v查看调用)

这是什么意思?

xcode nsautolayout swift

13
推荐指数
2
解决办法
2371
查看次数

在哪里更改"已安装"以进行自动布局约束?

在故事板中使用自动布局时,可以选择是否使用"已安装"复选框来安装约束.禁用它将导致它表现得就像你没有添加该约束 - 它将没有任何效果.您可以在Interface Builder中为不同大小的类配置已安装的状态,并且可以通过将其active属性设置为true或以编程方式更改此值false.

在我的应用程序中,我希望仅在设备处于纵向时安装约束 - 旋转到横向时应该"卸载".通过取消选中为任意宽度紧凑高度安装,可以为iPhone完成此操作.(虽然这似乎不太正常,因为当它甚至不应该安装时,由于在转向横向时出现冲突的约束而破坏了这个约束,但是无论UI总是按预期出现.)但是没有办法卸载Interface Builder中的横向iPad约束(两个方向的常规宽度常规高度).

哪里是合适的地方来启用/禁用activeNSLayoutConstraint轮值设备时?在什么轮换方法将改变该状态导致所需的行为 - 只安装为肖像?如果在启动应用程序时没有调用该方法,除了旋转方法之外还应该放置哪种方法?

我已尝试将以下代码放入其中viewDidLoad,viewWillTransitionToSize但这会导致在iPad上运行时出现一些意外行为:

  • 以横向方式启动应用程序会导致约束处于活动状态,尽管事件active设置为false,它会破坏约束,并且UI不会按预期显示
  • 以纵向方式启动应用程序将活动设置为true(它已经安装在IB中),因此它按预期工作
  • 以纵向方式启动应用程序并将设备旋转到横向按预期工作 - 约束设置为非活动状态,它不会破坏约束,UI显示为预期
  • 以纵向方式启动应用程序,旋转到横向以及返回到纵向会导致UI显示正确,但它会破坏设置为活动的此约束

如果我在Interface Builder中卸载约束然后运行上面的场景我基本上会得到相反的行为.

if size.width > size.height {
    self.myConstraint.active = false
} else {
    self.myConstraint.active = true
}
Run Code Online (Sandbox Code Playgroud)

screen-rotation ios autolayout nsautolayout ios8

11
推荐指数
1
解决办法
3899
查看次数

如何获得使用autolayout的NSTableCellView的高度

我有一个基于视图的NSTableView.我将textField其他元素NSTableCellView放在Interface Builder中的autolayout中.如何根据自动布局参数获取单元格的高度?

这个答案是我找到的最接近我要找的东西,但它是为iOS编写的,并且该systemLayoutSizeFittingSize方法不存在NSView.

macos nstableview autolayout nstablecellview nsautolayout

8
推荐指数
1
解决办法
1105
查看次数

在.xib中使用autolayout时出现奇怪的动画行为

我有一个自定义的tableview单元格,右对齐按钮有以下约束:

  1. 超视的尾随空间
  2. 固定宽度
  3. 固定高度
  4. 超级视图的顶层空间

在此输入图像描述

现在,当我启动视图控制器时,此编辑图标图像将飞行并在正确的位置安顿下来.如何删除该动画.

注意:此问题仅在某些单元格中可见.我也试过删除并重新添加组件.

objective-c uitableview ios autolayout nsautolayout

8
推荐指数
1
解决办法
267
查看次数

如何在父视图上添加子视图控制器的视图

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    ChildViewController *childviewcontroller = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];


    [self addChildViewController:childviewcontroller];
    [self.view addSubview:childviewcontroller.view];
    [childviewcontroller willMoveToParentViewController:self];
    UIView *cview = [[UIView alloc] init];
    cview = childviewcontroller.view;
    [self.view removeConstraints:self.view.constraints];

    NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(cview);
    [self.view addConstraints:[NSLayoutConstraint 
                                constraintsWithVisualFormat:@"H:|-[cview]-|" 
                                                    options:0 metrics:nil                                        
                                                    views:viewsDictionary]];

}
Run Code Online (Sandbox Code Playgroud)

我想在父视图上添加childviewcontroller视图.添加后我设置了约束,但它对我不起作用.

我也收到这样的警告

2013-07-25 10:47:30.564 neenah[1105:c07] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try …
Run Code Online (Sandbox Code Playgroud)

ios autolayout nsautolayout

7
推荐指数
1
解决办法
4243
查看次数

可视化格式语言,按钮宽度和高度约束

有没有办法用NSLayoutConstraints设置UIView的宽度和高度?例如,我有以下约束设置

subView.setTranslatesAutoresizingMaskIntoConstraints(false);
        let cons:NSArray =   NSLayoutConstraint.constraintsWithVisualFormat("[subView(99)]", options:nil, metrics: nil, views: ["subView":subView]);
        self.view.addConstraints(cons);
Run Code Online (Sandbox Code Playgroud)

这只设置宽度,如何添加高度?

objective-c ios nslayoutconstraint nsautolayout swift

7
推荐指数
2
解决办法
7625
查看次数