iOS-can';t使用progressView将约束设置为UIAlertController
我尝试使用约束将progressView放置在UIAlertController中,以便在iPhone或iPad上获得良好的视觉效果iOS-can';t使用progressView将约束设置为UIAlertController,ios,uialertcontroller,uiprogressview,Ios,Uialertcontroller,Uiprogressview,我尝试使用约束将progressView放置在UIAlertController中,以便在iPhone或iPad上获得良好的视觉效果 alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* cance
alert = [UIAlertController
alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* cancelButton = [UIAlertAction
actionWithTitle:titleCancel
style:UIAlertActionStyleDefault
handler:cancelBlock];
[alert addAction:cancelButton];
UIProgressView* progressView = [[UIProgressView alloc] init];
progressView.progress = 0.0;
progressView.tintColor = UIColor.blueColor;
[alert.view addSubview:progressView];
UILayoutGuide *margin = alert.view.layoutMarginsGuide;
[alert.view setAutoresizingMask:UIViewAutoresizingNone];
[progressView.heightAnchor constraintEqualToConstant:5].active = YES;
[progressView.widthAnchor constraintEqualToAnchor:margin.widthAnchor multiplier:0.75].active = YES;
[progressView.centerXAnchor constraintEqualToAnchor:margin.centerXAnchor].active = YES;
[progressView.centerYAnchor constraintEqualToAnchor:margin.centerYAnchor].active = YES;
[self presentViewController:alert animated:YES completion:nil];
我想实现这样的目标(que purple square支持alertViewController,只是一个示例…):
这是日志。。。我做错了什么。。。为什么会与约束发生冲突
2017-05-09 18:17:28.657982 Myapp[1457:1442554] [Common] _BSMachError: port a0a3; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2017-05-09 18:17:28.659300 Myapp[1457:1442554] [Common] _BSMachError: port a0a3; (os/kern) invalid name (0xf) "Unable to deallocate send right"
2017-05-09 18:17:28.709082 Myapp[1457:1442554] [LayoutConstraints] 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 translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x17048be00 h=--& v=--& UIProgressView:0x1013a44b0.height == 2 (active)>",
"<NSLayoutConstraint:0x17449cb60 UIProgressView:0x1013a44b0.height == 5 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17449cb60 UIProgressView:0x1013a44b0.height == 5 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-05-09 18:17:28.712681 Myapp[1457:1442554] [LayoutConstraints] 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 translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x170490310 h=--& v=--& UIProgressView:0x1013a44b0.midY == 1 (active)>",
"<NSLayoutConstraint:0x17449fef0 UIView:0x1013a56e0.height >= 44 (active)>",
"<NSLayoutConstraint:0x17449b2b0 _UIAlertControllerView:0x1013a5a40'Myapp'.height == UIView:0x1013a56e0.height (active)>",
"<NSLayoutConstraint:0x174681e50 UIProgressView:0x1013a44b0.centerY == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerY (active)>",
"<NSLayoutConstraint:0x174681e00 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide']-(8)-| (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>",
"<NSLayoutConstraint:0x174681bd0 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'] (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17449fef0 UIView:0x1013a56e0.height >= 44 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-05-09 18:17:28.715180 Myapp[1457:1442554] [LayoutConstraints] 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 translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x170490310 h=--& v=--& UIProgressView:0x1013a44b0.midY == 1 (active)>",
"<NSLayoutConstraint:0x174681e50 UIProgressView:0x1013a44b0.centerY == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerY (active)>",
"<NSLayoutConstraint:0x174681bd0 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'] (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174681e50 UIProgressView:0x1013a44b0.centerY == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerY (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-05-09 18:17:28.717844 Myapp[1457:1442554] [LayoutConstraints] 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 translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x170490f40 h=--& v=--& UIProgressView:0x1013a44b0.midX == 0 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x170495270 h=--& v=--& UIProgressView:0x1013a44b0.width == 0 (active)>",
"<NSLayoutConstraint:0x174681db0 UIProgressView:0x1013a44b0.width == 0.75*UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.width (active)>",
"<NSLayoutConstraint:0x174681f40 UIProgressView:0x1013a44b0.centerX == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerX (active)>",
"<NSLayoutConstraint:0x174681c20 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174681f40 UIProgressView:0x1013a44b0.centerX == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerX (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-05-09 18:17:28.720158 Myapp[1457:1442554] [LayoutConstraints] 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 translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x170495270 h=--& v=--& UIProgressView:0x1013a44b0.width == 0 (active)>",
"<NSLayoutConstraint:0x170288840 UIView:0x1013a56e0.width == 270 (active)>",
"<NSLayoutConstraint:0x174499eb0 _UIAlertControllerView:0x1013a5a40'Myapp'.width >= UIView:0x1013a56e0.width (active)>",
"<NSLayoutConstraint:0x174681db0 UIProgressView:0x1013a44b0.width == 0.75*UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.width (active)>",
"<NSLayoutConstraint:0x174681c20 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>",
"<NSLayoutConstraint:0x174681f90 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide']-(8)-|(LTR) (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170288840 UIView:0x1013a56e0.width == 270 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-05-09 18:17:28.657982 Myapp[1457:1442554][Common]\u bsmach错误:端口a0a3;(os/kern)无效功能(0x14)“无法插入副本\u发送”
2017-05-09 18:17:28.659300 Myapp[1457:1442554][Common](常见错误:端口a0a3;(os/kern)无效名称(0xf)“无法取消分配发送权限”
2017-05-09 18:17:28.709082 Myapp[1457:1442554][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2017-05-09 18:17:28.712681 Myapp[1457:1442554][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
“=44(激活)>”,
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
=44(有效)>
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2017-05-09 18:17:28.715180 Myapp[1457:1442554][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2017-05-09 18:17:28.717844 Myapp[1457:1442554][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2017-05-09 18:17:28.720158 Myapp[1457:1442554][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
“=UIView:0x1013a56e0.width(活动)>”,
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
首先,我不认为在进度视图中添加约束是个好主意。因为它被添加到呈现的UIAlertController中
如果要添加progressView,则需要跟踪进度并更新需要在主线程上完成的进度,因此每次执行任何繁重的操作时,都可能会影响UI更新(进度)。这必须由GCD妥善处理
下面的方法将有助于解决您的问题
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController * alertCont = [UIAlertController alertControllerWithTitle:@"Test" message:@"Test message" preferredStyle:UIAlertControllerStyleAlert];
UIProgressView * progresbar = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
[progresbar setProgress:5.0 animated:YES];
progresbar.frame = CGRectMake(10, 40, 250, 0);
[alertCont.view addSubview:progresbar];
[topController presentViewController:alertCont animated:YES completion:nil];
});
您不应该设置相对于AlertviewController视图的约束。而是使用AlertviewController->View->SubView[0]来设置约束 例如,要设置UIAlertController的宽度,请执行以下操作:
for constraint in self.alertView.subviews[0].constraints {
if constraint.firstAttribute == NSLayoutAttribute.width && constraint.constant == 270{
NSLayoutConstraint.deactivate([constraint])
break
}
}
let widthConstraint:NSLayoutConstraint = NSLayoutConstraint(item: self.view.subviews[0], attribute:
NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 120.0)
self.alertview.subviews[0].addConstraint(widthConstraint)
UIAlertController
不是为定制而设计的。这种方法的问题是使用了幻数。另外,这在iPad或landscap上也不能正常工作