iOS 7 では、Web ビューのフレームを変更した後、Web ビューがそのスーパービュー (次のコードの Web ビュー コンテナー) のこの位置にあることを確認するために、いくつかの制約を追加しようとしています。また、正しい垂直スクロール インジケーターを表示できるように、Web ビュー内のスクロール ビューが Web ビューと同じ境界に一致するようにしたいと考えています。そのスーパービュー (アプリケーション ウィンドウのルート ビュー コントローラーのビュー) に関する Web ビュー コンテナーのフレームは、擬似コード(origin.x = 0, origin.y = 20, size.width = 320, size.height = 568 - 20 = 548)
です。
コードは、上記の制約を追加するために私が作成したものです。
コードを実行したときに受け取ったエラー メッセージ。新しい制約を追加して古い制約を置き換えることができない理由がわかりません。問題は、古い制約を自分で作成していないことです。知らない場所に自動的に生成されます。これが何を意味するかなど、エラーメッセージも理解できませんNSAutoresizingMaskLayoutConstraint:0xc17e930 h=--& v=--& UIWebView:0xc06b020.midY == + 274
。
コード
[[_webViewContainer webView] addConstraint:
[NSLayoutConstraint constraintWithItem:[[_webViewContainer webView] scrollView]
attribute:NSLayoutAttributeTop
relatedBy:0
toItem:[_webViewContainer webView]
attribute:NSLayoutAttributeTop
multiplier:1
constant:0]];
[[_webViewContainer webView] addConstraint:
[NSLayoutConstraint constraintWithItem:[[_webViewContainer webView] scrollView]
attribute:NSLayoutAttributeBottom
relatedBy:0
toItem:[_webViewContainer webView]
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0]];
[[_webViewContainer webView] addConstraint:
[NSLayoutConstraint constraintWithItem:[[_webViewContainer webView] scrollView]
attribute:NSLayoutAttributeLeft
relatedBy:0
toItem:[_webViewContainer webView]
attribute:NSLayoutAttributeLeft
multiplier:1
constant:0]];
[[_webViewContainer webView] addConstraint:
[NSLayoutConstraint constraintWithItem:[[_webViewContainer webView] scrollView]
attribute:NSLayoutAttributeRight
relatedBy:0
toItem:[_webViewContainer webView]
attribute:NSLayoutAttributeRight
multiplier:1
constant:0]];
[[_webViewContainer webView] setNeedsUpdateConstraints];
[[_webViewContainer webView] layoutSubviews];
[_webViewContainer addConstraint:
[NSLayoutConstraint constraintWithItem:[_webViewContainer webView]
attribute:NSLayoutAttributeTop
relatedBy:0
toItem:_webViewContainer
attribute:NSLayoutAttributeTop
multiplier:1
constant:45]];
[_webViewContainer addConstraint:
[NSLayoutConstraint constraintWithItem:[_webViewContainer webView]
attribute:NSLayoutAttributeBottom
relatedBy:0
toItem:_webViewContainer
attribute:NSLayoutAttributeBottom
multiplier:1
constant:-49]];
[_webViewContainer addConstraint:
[NSLayoutConstraint constraintWithItem:[_webViewContainer webView]
attribute:NSLayoutAttributeLeft
relatedBy:0
toItem:_webViewContainer
attribute:NSLayoutAttributeLeft
multiplier:1
constant:0]];
[_webViewContainer addConstraint:
[NSLayoutConstraint constraintWithItem:[_webViewContainer webView]
attribute:NSLayoutAttributeRight
relatedBy:0
toItem:_webViewContainer
attribute:NSLayoutAttributeRight
multiplier:1
constant:0]];
[_webViewContainer setNeedsUpdateConstraints];
[_webViewContainer layoutSubviews];
エラー メッセージ
2013-11-05 21:32:03.422 emptyproject[16471:70b] 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:0xc17e930 h=--& v=--& UIWebView:0xc06b020.midY == + 274>",
"<NSAutoresizingMaskLayoutConstraint:0xc17e960 h=--& v=--& V:[UIWebView:0xc06b020(454)]>",
"<NSLayoutConstraint:0xc1803f0 V:|-(45)-[UIWebView:0xc06b020] (Names: '|':UIViewWebViewContainer:0xbfb76d0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xc1803f0 V:|-(45)-[UIWebView:0xc06b020] (Names: '|':UIViewWebViewContainer:0xbfb76d0 )>
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.
2013-11-05 21:32:03.423 emptyproject[16471:70b] 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:0xc17e930 h=--& v=--& UIWebView:0xc06b020.midY == + 274>",
"<NSAutoresizingMaskLayoutConstraint:0xc17e960 h=--& v=--& V:[UIWebView:0xc06b020(454)]>",
"<NSAutoresizingMaskLayoutConstraint:0xc17ed80 h=--& v=--& V:[UIViewWebViewContainer:0xbfb76d0(548)]>",
"<NSLayoutConstraint:0xc1802b0 UIWebView:0xc06b020.bottom == UIViewWebViewContainer:0xbfb76d0.bottom - 49>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xc1802b0 UIWebView:0xc06b020.bottom == UIViewWebViewContainer:0xbfb76d0.bottom - 49>
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.
2013-11-05 21:32:03.424 emptyproject[16471:70b] 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:0xc17e930 h=--& v=--& UIWebView:0xc06b020.midY == + 274>",
"<NSAutoresizingMaskLayoutConstraint:0xc17e960 h=--& v=--& V:[UIWebView:0xc06b020(548)]>",
"<NSLayoutConstraint:0xc1803f0 V:|-(45)-[UIWebView:0xc06b020] (Names: '|':UIViewWebViewContainer:0xbfb76d0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xc1803f0 V:|-(45)-[UIWebView:0xc06b020] (Names: '|':UIViewWebViewContainer:0xbfb76d0 )>
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.
2013-11-05 21:32:16.334 emptyproject[16471:70b] web view container (Drawer.m handleLogoutScheme line 938) origin x = 0.000000, origin y = 20.000000, width = 320.000000, height = 548.000000 in the coordinate system of web view container's superview
2013-11-05 21:32:16.336 emptyproject[16471:4707] void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
2013-11-05 21:32:24.822 emptyproject[16471:70b] web view container (Drawer.m handleLoginScheme line 860) origin x = 0.000000, origin y = 20.000000, width = 320.000000, height = 548.000000 in the coordinate system of web view container's superview
2013-11-05 21:32:24.823 emptyproject[16471:70b] [[_webViewContainer webView] constraints] = (
"<NSLayoutConstraint:0xc168600 V:|-(0)-[_UIWebViewScrollView:0xbfb8220] (Names: '|':UIWebView:0xc06b020 )>",
"<NSLayoutConstraint:0xc17d780 _UIWebViewScrollView:0xbfb8220.bottom == UIWebView:0xc06b020.bottom>",
"<NSLayoutConstraint:0xc17db20 H:|-(0)-[_UIWebViewScrollView:0xbfb8220](LTR) (Names: '|':UIWebView:0xc06b020 )>",
"<NSLayoutConstraint:0xc17dce0 _UIWebViewScrollView:0xbfb8220.right == UIWebView:0xc06b020.right>",
"<NSAutoresizingMaskLayoutConstraint:0xc17dfa0 h=--& v=-&- _UIWebViewScrollView:0xbfb8220.midX == + 160>",
"<NSAutoresizingMaskLayoutConstraint:0xc17e0c0 h=--& v=-&- H:[_UIWebViewScrollView:0xbfb8220(320)]>",
"<NSAutoresizingMaskLayoutConstraint:0xc17e0f0 h=--& v=-&- _UIWebViewScrollView:0xbfb8220.midY == UIWebView:0xc06b020.midY>",
"<NSAutoresizingMaskLayoutConstraint:0xc17e220 h=--& v=-&- _UIWebViewScrollView:0xbfb8220.height == UIWebView:0xc06b020.height>"
)