自上周以来我一直试图解决这个问题,而没有更进一步.好的,所以我需要在Swift中以编程方式应用一些约束 来使用这段代码:UIView
var new_view:UIView! = UIView(frame: CGRectMake(0, 0, 100, 100));
new_view.backgroundColor = UIColor.redColor();
view.addSubview(new_view);
var constX:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0);
self.view.addConstraint(constX);
var constY:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0);
self.view.addConstraint(constY);
var constW:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: new_view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0);
self.view.addConstraint(constW);
var constH:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: …Run Code Online (Sandbox Code Playgroud) 我在通用应用程序的底部显示一个视图,并在我的视图中动态添加此视图.我希望每次都像iAd一样在底部显示这个视图.在两个方向.如何为此添加约束.请建议.
谢谢
我有一个子视图,我想在旋转屏幕期间保持停止,所以我决定将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) 我有一个UIImageView嵌入式UIView.我的整个应用程序使用AutoLayout,但我想删除constraints的UIImageView.Xcode不会允许我删除constraints,有没有办法为特定对象禁用它们,将它们设置为零,什么?
我在iOS 8中遇到动态大小的tableViewCell问题.虽然它在视觉上看起来很好,但我得到了带有AutoLayout错误的日志输出.我把它简化为这个简单的例子.
我正在为我的手机添加一个UILabel:
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.titleLabel.numberOfLines = 0;
self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
[self.contentView addSubview:self.titleLabel];
Run Code Online (Sandbox Code Playgroud)
我在代码中创建我的自动布局的限制,采用砌体中updateConstraints:
[self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[self.titleLabel updateConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.contentView.leading).with.offset(padding.left);
make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right);
make.top.equalTo(self.contentView.top).with.offset(padding.top);
make.bottom.equalTo(self.contentView.bottom).with.offset(-padding.bottom / 2);
}];
Run Code Online (Sandbox Code Playgroud)
(我可以用make.edges一步完成,但问题是一样的)
这最初看起来很好.然后,当我对tableview执行任何修改并调用[tableView endUpdates](可能是触发updateContraints)时,我在控制台日志中得到以下内容:
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 …Run Code Online (Sandbox Code Playgroud) 我正在开发一个动态应用程序,在该应用程序中,我CGRect从Web服务中为视图中的每个UI对象分别获取(x,y,width,height)值.
在服务器上,他们将根据以下尺寸(1080 x 1920)设置帧,所以假设,如果我得到CGRect以下值:(200,20,100,100)那么它应该适合基于设备的设备大小和服务器指定的大小.
因此,对于iPhone 5的情况 - 新的框架将是相同的200,20,100,100.
因此,对于iPhone 6(375 x 667)的情况 - 新的框架将是?
因此,对于iPhone 6+(414 x 736)的情况 - 新的框架将是?
最重要的是,无论框架将被接收到特定UI对象的应用程序中,它应该与管理面板中的内容完全相同,特别是对于边距.
如需说明,
我只在Storyboard中使用AutoLayout设置UI.
有什么建议吗?
这是一个例子:
例1:
| _________________ |
| | | |
| | | |
| | | |
| | | |
| |_________________| |
| |
Run Code Online (Sandbox Code Playgroud)
例2:
| _________ |
| | | |
| | | |
| | | |
| | | |
| |_________| |
| |
Run Code Online (Sandbox Code Playgroud)
通过上面的例子,我试图解释一下,无论来自服务器的帧是什么,如果在服务器上看起来如此,类似的将在设备上,但它应该基于设备 …
autolayout ×5
ios ×5
constraints ×3
iphone ×3
objective-c ×2
uiview ×2
ios8 ×1
layout ×1
swift ×1
uiimageview ×1
uitableview ×1