标签: autolayout

今天iPad的扩展高度远大于指定

My Today扩展需要基于窗口小部件显示的内容具有动态高度.我能够通过在最底部元素上添加约束来实现这一点:底部布局指南的顶部小于或等于最底部元素的底部,常量为0,优先级为999,乘数为1.

这与iPhone上的预期完全一样 - 小部件高度适合所有内容,并且在显示下一个小部件之前应用默认的底部边距.

但是在iPad上似乎将我的小部件的高度设置为等于最大高度通知中心将允许小部件 - 我的小部件下方有很多空间,它几乎全屏.

如何删除多余的空间?

我确切地知道问题是什么,但我不确定如何解决它 - 请参阅"问题"部分.首先让我解释一下设置:

设置:
我在故事板中设置了此扩展的视图,没有任何编程方式.视图由垂直堆叠的5个元素组成,其他一些元素水平堆叠.这些是从上到下的垂直线的自动布局约束 - 其中未声明的优先级为1000,乘数1:

UILabel: height = 35, top space to top layout guide with constant of 10
UIButton: equal height and width to a different button (whose aspect ratio is 1:1, there is no fixed width/height), top space to label 10
UIButton: equal height and width to same button, top space to above button 8
UIButton: equal height and width to same button, top space to above …
Run Code Online (Sandbox Code Playgroud)

ios autolayout ios8 ios-app-extension ios8-today-widget

51
推荐指数
1
解决办法
1511
查看次数

'NSInvalidArgumentException',原因:'无法解析约束格式'

我有一个子视图,我想在旋转屏幕期间保持停止,所以我决定将NSLayoutConstraint类型:

尾随空间到Superview
顶部空间到Superview
按钮空间到Superview
我在UITableViewCell的子类中.我写了代码,但是我收到以下错误:

'NSInvalidArgumentException', reason: 'Unable to parse constraint format: 
 self is not a key in the views dictionary. 
 H:[self.arrows]-5-|
Run Code Online (Sandbox Code Playgroud)


我在CustomCell.m中的代码是:

 self.arrows = [[Arrows alloc]initWithFrame:CGRectMake(self.contentView.bounds.size.width-30, self.bounds.origin.y+4, 30, self.contentView.bounds.size.height-4)];

 NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(self.arrows, self.contentView);
 NSMutableArray * constraint=[[NSMutableArray alloc]init];
 [constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:  [self.arrows]-5-|" options:0 metrics:nil views:viewsDictionary]];
 [constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-1-[self.arrows]" options:0 metrics:nil views:viewsDictionary]];
 [constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"[V: [self.arrows]-1-|" options:0 metrics:nil views:viewsDictionary]];
 [self.arrows addConstraints:constraint];
Run Code Online (Sandbox Code Playgroud)

layout compiler-errors constraints ios autolayout

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

删除特定对象的自动布局约束

我有一个UIImageView嵌入式UIView.我的整个应用程序使用AutoLayout,但我想删除constraintsUIImageView.Xcode不会允许我删除constraints,有没有办法为特定对象禁用它们,将它们设置为零,什么?

iphone uiview uiimageview autolayout

50
推荐指数
5
解决办法
7万
查看次数

ScrollView具有不明确的可滚动内容高度

我正在进行一个非常基本的UIScrollView测试.这是我的设置在此输入图像描述 它向我显示以下AutoLayout错误:

ScrollView has ambiguous scrollable content height 
Run Code Online (Sandbox Code Playgroud)

uiscrollview ios autolayout

50
推荐指数
1
解决办法
6万
查看次数

使用自动布局,如何根据图像使UIImageView的大小动态?

我希望我UIImageView的增长或缩小取决于它显示的实际图像的大小.但我希望它保持垂直居中,距离超视距的前沿10分钟.

但是,如果我设置这两个约束,它会抱怨我没有设置足够的约束来满足自动布局.对我来说,它似乎完美地描述了我想要的东西.我错过了什么?

objective-c uiimageview ios autolayout nslayoutconstraint

50
推荐指数
4
解决办法
5万
查看次数

以编程方式更新高度约束

我是汽车布局的新手.我已经完成了xib文件中的所有项目,但现在我遇到了一个问题,我必须以编程方式更新视图的高度.我试过下面但现在正在努力.

[[self view] addConstraint:[NSLayoutConstraint constraintWithItem:loginContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:loginFrame.size.height]];
Run Code Online (Sandbox Code Playgroud)

在控制台中显示

Unable to simultaneously satisfy constraints.
    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 …
Run Code Online (Sandbox Code Playgroud)

objective-c ios autolayout nslayoutconstraint swift

50
推荐指数
5
解决办法
6万
查看次数

如何调整JavaFX ScrollPane内容的大小以适应当前大小

我有一个BorderPaneScrollPane为中心元素.它会自动调整大小以填充屏幕.里面ScrollPane是一个HBox没有内容但是是一个拖放目标.因此,我希望它填补其父母ScrollPane.

这样做的首选方法是什么?

到目前为止我所尝试的是重写ScrollPane.resize(...)调整大小的方法,HBox但它似乎相当复杂和非正统.

编辑:要为此添加一些有用的代码,这就是我可以解决问题的方法,但我相信必须有更好的方法来做到这一点:

@Override
public void resize(double width, double height) {
    super.resize(width, height);

    double scrollBarHeight = 2;
    double scrollBarWidth = 2;

    for (final Node node : lookupAll(".scroll-bar")) {
        if (node instanceof ScrollBar) {
            ScrollBar sb = (ScrollBar) node;
            if (sb.getOrientation() == Orientation.HORIZONTAL) {
                System.out.println("horizontal scrollbar visible = " + sb.isVisible());
                System.out.println("width = " + sb.getWidth());
                System.out.println("height = " + sb.getHeight());
                if(sb.isVisible()){
                    scrollBarHeight = sb.getHeight();
                } …
Run Code Online (Sandbox Code Playgroud)

resize javafx scrollpane autolayout

49
推荐指数
2
解决办法
4万
查看次数

AutoLayout可保持视图大小成比例

我正在努力实现以下目标:

  • 我的xib中有2个视图需要保持20个像素的边缘(两侧和顶部)
  • 需要调整大小的2个视图的大小不同
  • 它们必须相隔20个像素
  • 它们的宽度需要相对于父视图的宽度保持不变

我阅读了一个关于这样做的教程并且它可以工作,但问题是它需要两个视图具有相同的宽度和引脚Widths equally,这是我不想要的.

这是我试过的:

  • 将前导空间约束添加到左视图为20像素
  • 将顶部空间约束添加到左视图为20像素
  • 将顶部空间约束添加到右视图为20像素
  • 将尾部空间约束添加到右视图为20像素
  • 将水平间距约束添加到两个视图为20像素

我遇到的问题是左视图没有调整大小,右视图填充空间以保持20像素的水平空间.

有没有办法让两个视图按比例调整它们应该填充的空间?

以下是我的布局和约束的屏幕截图:

xib布局约束定义

谢谢!

编辑

我尝试旋转设备时收到以下警告:

2012-10-11 08:59:00.435 AutolayoutTest[35672:c07] Unable to simultaneously satisfy constraints.
    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 …
Run Code Online (Sandbox Code Playgroud)

interface-builder ios autolayout ios6 nslayoutconstraint

48
推荐指数
5
解决办法
6万
查看次数

什么是'UIView-Encapsulated-Layout-Width'约束?

我一直得到'无法同时满足约束'的例外(Xcode 5,iOS 7,设备和模拟器),其中列表中的一个约束是这样的:

"<NSLayoutConstraint:0x165b23d0 'UIView-Encapsulated-Layout-Width'
H:[StoryPlayerCell:0x165affc0(0)]>"
Run Code Online (Sandbox Code Playgroud)

我自己没有设置这个约束.它也不是NSAutoresizingMaskLayoutConstraint.但是它来自哪里?我怎么能摆脱它呢?

我不知道.我'UIView-Encapsulated-Layout-Width'在Apple的文档中找不到任何相关内容.即便是谷歌搜索也没有任何回报.

有什么建议?

PS:我在UICollectionView一个自定义子类中使用这个单元格UICollectionViewFlowLayout.也许这'Encapsulated-Layout'部分与此有关?

ios autolayout uicollectionview nslayoutconstraint uicollectionviewlayout

48
推荐指数
2
解决办法
1万
查看次数

我可以使用autolayout为横向和纵向方向提供不同的约束吗?

设备旋转时是否可以更改约束?怎么可能实现这一目标?

一个简单的例子可能是两个图像,它们在纵向上一个堆叠在另一个之上,但在景观中是并排的.

如果这是不可能的,我怎么可能完成这个布局?

我正在构建代码中的视图和约束,而不是使用接口构建器.

cocoa-touch uiviewcontroller uiview ios autolayout

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