How do I convert constraints's toItem or Item from viewA to viewB? I am getting this error: Unknown layout attributeHow to call Objective-C code from SwiftDownload data and display itSwift UIAlertController causing Autolayout Engine warningUITabBarItem action giving NSExceptionUIKit UIViewReportBrokenSuperviewChain exceptionCrashing app in XcodeNot able to Switch between View controllers ProgramaticallyUnrecognized selector sent to instance 0x7f995be07650Error in Swift Code?Getting UITableView error “unable to dequeue a cell with identifier cell”
Non-OR journals which regularly publish OR research
Are any jet engines used in combat aircraft water cooled?
What is my malfunctioning AI harvesting from humans?
Y2K... in 2019?
Why should we care about syntactic proofs if we can show semantically that statements are true?
Why are the inside diameters of some pipe larger than the stated size?
Why are Gatwick's runways too close together?
Why did Gandalf use a sword against the Balrog?
How do I explain to a team that the project they will work on for six months will certainly be cancelled?
Does the United States guarantee any unique freedoms?
What is the idiomatic way of saying “he is ticklish under armpits”?
Is refreshing multiple times a test case for web applications?
Does two puncture wounds mean venomous snake?
How many different ways are there to checkmate in the early game?
Was the 2019 Lion King film made through motion capture?
What are good ways to improve as a writer other than writing courses?
Plausibility of Ice Eaters in the Arctic
How do we avoid CI-driven development...?
Does a code snippet compile? Or does it get compiled?
sed delete all the words before a match
Acceptable to cut steak before searing?
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
If a Contingency spell has been cast on a creature, does the Simulacrum spell transfer the contingent spell to its duplicate?
Can a one way NS Ticket be used as an OV-Chipkaart for P+R Parking in Amsterdam?
How do I convert constraints's toItem or Item from viewA to viewB? I am getting this error: Unknown layout attribute
How to call Objective-C code from SwiftDownload data and display itSwift UIAlertController causing Autolayout Engine warningUITabBarItem action giving NSExceptionUIKit UIViewReportBrokenSuperviewChain exceptionCrashing app in XcodeNot able to Switch between View controllers ProgramaticallyUnrecognized selector sent to instance 0x7f995be07650Error in Swift Code?Getting UITableView error “unable to dequeue a cell with identifier cell”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
As title, I have the viewParent which has viewA,
but viewA will be replaced by viewB within method awakeAfter
.
I wanna convert all of constraints
from viewParent <-> viewA,
to viewParent <-> viewB.
Thanks a lots.
Here is my code:
private func convertConstraints(from: UIView, to: UIView)
from.constraints.forEach (constraint: NSLayoutConstraint) in
let isFirst = (constraint.firstItem as? UIView) == from
let isSecond = (constraint.secondItem as? UIView) == from
let first: Any = (isFirst) ? to : constraint.firstItem as Any
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
let new = NSLayoutConstraint(item: first,
attribute: constraint.firstAttribute,
relatedBy: constraint.relation,
toItem: second,
attribute: constraint.secondAttribute,
multiplier: constraint.multiplier,
constant: constraint.constant)
new.priority = constraint.priority
new.identifier = constraint.identifier
new.shouldBeArchived = constraint.shouldBeArchived
new.isActive = constraint.isActive
And console log is below:
2019-03-27 15:36:33.740004+0800 Cale[86571:50392102] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <Cale.AirportButton: 0x7f9eb454d990; baseClass = UIButton; frame = (0 129; 120 120); autoresize = RM+BM; layer = <CALayer: 0x600003936460>>: Unknown layout attribute'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bf501bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010b4ee735 objc_exception_throw + 48
2 CoreFoundation 0x000000010bf50015 +[NSException raise:format:] + 197
3 Foundation 0x000000010a16cf61 ResolveConstraintArguments + 372
4 Foundation 0x000000010a16d2cb +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:] + 80
.
.
.
swift
add a comment |
As title, I have the viewParent which has viewA,
but viewA will be replaced by viewB within method awakeAfter
.
I wanna convert all of constraints
from viewParent <-> viewA,
to viewParent <-> viewB.
Thanks a lots.
Here is my code:
private func convertConstraints(from: UIView, to: UIView)
from.constraints.forEach (constraint: NSLayoutConstraint) in
let isFirst = (constraint.firstItem as? UIView) == from
let isSecond = (constraint.secondItem as? UIView) == from
let first: Any = (isFirst) ? to : constraint.firstItem as Any
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
let new = NSLayoutConstraint(item: first,
attribute: constraint.firstAttribute,
relatedBy: constraint.relation,
toItem: second,
attribute: constraint.secondAttribute,
multiplier: constraint.multiplier,
constant: constraint.constant)
new.priority = constraint.priority
new.identifier = constraint.identifier
new.shouldBeArchived = constraint.shouldBeArchived
new.isActive = constraint.isActive
And console log is below:
2019-03-27 15:36:33.740004+0800 Cale[86571:50392102] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <Cale.AirportButton: 0x7f9eb454d990; baseClass = UIButton; frame = (0 129; 120 120); autoresize = RM+BM; layer = <CALayer: 0x600003936460>>: Unknown layout attribute'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bf501bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010b4ee735 objc_exception_throw + 48
2 CoreFoundation 0x000000010bf50015 +[NSException raise:format:] + 197
3 Foundation 0x000000010a16cf61 ResolveConstraintArguments + 372
4 Foundation 0x000000010a16d2cb +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:] + 80
.
.
.
swift
Why don't you just remove the constraints and add them to the second view? make sure to add the constraints to the needed view after adding the view
– Sanad Barjawi
Mar 27 at 7:48
Instead of replacing the view. Create a container remove and add the required views from it.
– Sachin Vas
Mar 27 at 8:12
Because both of viewA which is initialized from code and viewB is loaded from Nib are the same class. And yes, I can remove the constraints but I also need add same them to the second view like the method doing.
– Wei
Mar 27 at 8:15
I'm based on following link and trying to refactor it. Creating custom UI components in iOS with Swift
– Wei
Mar 27 at 8:17
add a comment |
As title, I have the viewParent which has viewA,
but viewA will be replaced by viewB within method awakeAfter
.
I wanna convert all of constraints
from viewParent <-> viewA,
to viewParent <-> viewB.
Thanks a lots.
Here is my code:
private func convertConstraints(from: UIView, to: UIView)
from.constraints.forEach (constraint: NSLayoutConstraint) in
let isFirst = (constraint.firstItem as? UIView) == from
let isSecond = (constraint.secondItem as? UIView) == from
let first: Any = (isFirst) ? to : constraint.firstItem as Any
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
let new = NSLayoutConstraint(item: first,
attribute: constraint.firstAttribute,
relatedBy: constraint.relation,
toItem: second,
attribute: constraint.secondAttribute,
multiplier: constraint.multiplier,
constant: constraint.constant)
new.priority = constraint.priority
new.identifier = constraint.identifier
new.shouldBeArchived = constraint.shouldBeArchived
new.isActive = constraint.isActive
And console log is below:
2019-03-27 15:36:33.740004+0800 Cale[86571:50392102] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <Cale.AirportButton: 0x7f9eb454d990; baseClass = UIButton; frame = (0 129; 120 120); autoresize = RM+BM; layer = <CALayer: 0x600003936460>>: Unknown layout attribute'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bf501bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010b4ee735 objc_exception_throw + 48
2 CoreFoundation 0x000000010bf50015 +[NSException raise:format:] + 197
3 Foundation 0x000000010a16cf61 ResolveConstraintArguments + 372
4 Foundation 0x000000010a16d2cb +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:] + 80
.
.
.
swift
As title, I have the viewParent which has viewA,
but viewA will be replaced by viewB within method awakeAfter
.
I wanna convert all of constraints
from viewParent <-> viewA,
to viewParent <-> viewB.
Thanks a lots.
Here is my code:
private func convertConstraints(from: UIView, to: UIView)
from.constraints.forEach (constraint: NSLayoutConstraint) in
let isFirst = (constraint.firstItem as? UIView) == from
let isSecond = (constraint.secondItem as? UIView) == from
let first: Any = (isFirst) ? to : constraint.firstItem as Any
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
let new = NSLayoutConstraint(item: first,
attribute: constraint.firstAttribute,
relatedBy: constraint.relation,
toItem: second,
attribute: constraint.secondAttribute,
multiplier: constraint.multiplier,
constant: constraint.constant)
new.priority = constraint.priority
new.identifier = constraint.identifier
new.shouldBeArchived = constraint.shouldBeArchived
new.isActive = constraint.isActive
And console log is below:
2019-03-27 15:36:33.740004+0800 Cale[86571:50392102] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <Cale.AirportButton: 0x7f9eb454d990; baseClass = UIButton; frame = (0 129; 120 120); autoresize = RM+BM; layer = <CALayer: 0x600003936460>>: Unknown layout attribute'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bf501bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010b4ee735 objc_exception_throw + 48
2 CoreFoundation 0x000000010bf50015 +[NSException raise:format:] + 197
3 Foundation 0x000000010a16cf61 ResolveConstraintArguments + 372
4 Foundation 0x000000010a16d2cb +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:] + 80
.
.
.
swift
swift
edited Mar 27 at 8:44
Chitra Khatri
9751 gold badge12 silver badges30 bronze badges
9751 gold badge12 silver badges30 bronze badges
asked Mar 27 at 7:45
WeiWei
417 bronze badges
417 bronze badges
Why don't you just remove the constraints and add them to the second view? make sure to add the constraints to the needed view after adding the view
– Sanad Barjawi
Mar 27 at 7:48
Instead of replacing the view. Create a container remove and add the required views from it.
– Sachin Vas
Mar 27 at 8:12
Because both of viewA which is initialized from code and viewB is loaded from Nib are the same class. And yes, I can remove the constraints but I also need add same them to the second view like the method doing.
– Wei
Mar 27 at 8:15
I'm based on following link and trying to refactor it. Creating custom UI components in iOS with Swift
– Wei
Mar 27 at 8:17
add a comment |
Why don't you just remove the constraints and add them to the second view? make sure to add the constraints to the needed view after adding the view
– Sanad Barjawi
Mar 27 at 7:48
Instead of replacing the view. Create a container remove and add the required views from it.
– Sachin Vas
Mar 27 at 8:12
Because both of viewA which is initialized from code and viewB is loaded from Nib are the same class. And yes, I can remove the constraints but I also need add same them to the second view like the method doing.
– Wei
Mar 27 at 8:15
I'm based on following link and trying to refactor it. Creating custom UI components in iOS with Swift
– Wei
Mar 27 at 8:17
Why don't you just remove the constraints and add them to the second view? make sure to add the constraints to the needed view after adding the view
– Sanad Barjawi
Mar 27 at 7:48
Why don't you just remove the constraints and add them to the second view? make sure to add the constraints to the needed view after adding the view
– Sanad Barjawi
Mar 27 at 7:48
Instead of replacing the view. Create a container remove and add the required views from it.
– Sachin Vas
Mar 27 at 8:12
Instead of replacing the view. Create a container remove and add the required views from it.
– Sachin Vas
Mar 27 at 8:12
Because both of viewA which is initialized from code and viewB is loaded from Nib are the same class. And yes, I can remove the constraints but I also need add same them to the second view like the method doing.
– Wei
Mar 27 at 8:15
Because both of viewA which is initialized from code and viewB is loaded from Nib are the same class. And yes, I can remove the constraints but I also need add same them to the second view like the method doing.
– Wei
Mar 27 at 8:15
I'm based on following link and trying to refactor it. Creating custom UI components in iOS with Swift
– Wei
Mar 27 at 8:17
I'm based on following link and trying to refactor it. Creating custom UI components in iOS with Swift
– Wei
Mar 27 at 8:17
add a comment |
1 Answer
1
active
oldest
votes
I fixed it,... thanks a lot.
I modified code from:
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
to:
let second: Any? = (isSecond) ? to : constraint.secondItem
type Optional<Any?> v.s. Any?
– Wei
Mar 27 at 8:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372094%2fhow-do-i-convert-constraintss-toitem-or-item-from-viewa-to-viewb-i-am-getting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I fixed it,... thanks a lot.
I modified code from:
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
to:
let second: Any? = (isSecond) ? to : constraint.secondItem
type Optional<Any?> v.s. Any?
– Wei
Mar 27 at 8:51
add a comment |
I fixed it,... thanks a lot.
I modified code from:
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
to:
let second: Any? = (isSecond) ? to : constraint.secondItem
type Optional<Any?> v.s. Any?
– Wei
Mar 27 at 8:51
add a comment |
I fixed it,... thanks a lot.
I modified code from:
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
to:
let second: Any? = (isSecond) ? to : constraint.secondItem
I fixed it,... thanks a lot.
I modified code from:
let second: Any? = (isSecond) ? to : constraint.secondItem as? Any
to:
let second: Any? = (isSecond) ? to : constraint.secondItem
answered Mar 27 at 8:50
WeiWei
417 bronze badges
417 bronze badges
type Optional<Any?> v.s. Any?
– Wei
Mar 27 at 8:51
add a comment |
type Optional<Any?> v.s. Any?
– Wei
Mar 27 at 8:51
type Optional<Any?> v.s. Any?
– Wei
Mar 27 at 8:51
type Optional<Any?> v.s. Any?
– Wei
Mar 27 at 8:51
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372094%2fhow-do-i-convert-constraintss-toitem-or-item-from-viewa-to-viewb-i-am-getting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why don't you just remove the constraints and add them to the second view? make sure to add the constraints to the needed view after adding the view
– Sanad Barjawi
Mar 27 at 7:48
Instead of replacing the view. Create a container remove and add the required views from it.
– Sachin Vas
Mar 27 at 8:12
Because both of viewA which is initialized from code and viewB is loaded from Nib are the same class. And yes, I can remove the constraints but I also need add same them to the second view like the method doing.
– Wei
Mar 27 at 8:15
I'm based on following link and trying to refactor it. Creating custom UI components in iOS with Swift
– Wei
Mar 27 at 8:17