Compact Regular size change via rotation = Unable to simultaneously satisfy constraints when using...
up vote
2
down vote
favorite
I have defined four buttons programmatically and added them to UIStackview name 'finalStack'. During rotation I am able to successfully change finalStack orientation but I am unable to move it after adjusting centerY-anchor value. From the console, I have errors stating that I am failing to remove the previous constraints. Is my code to de-activate the constraints incorrect or am I missing something else? The two print statements in my if/else statement tell me that I am correctly hitting the appropriate code block after rotating device.
Simulator is using iPhone XR
In the meantime I'm trying to follow the recommendations and trying to implement symbolic breakpoints but that topic is turning into another major task for me. Would greatly appreciate any insight into either topic. Console Warnings after device rotates
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.red
finalStack.addArrangedSubview(buttonOne)
finalStack.addArrangedSubview(buttonTwo)
finalStack.addArrangedSubview(buttonThree)
finalStack.addArrangedSubview(buttonFour)
view.addSubview(finalStack)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let compactContraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
let regularConstraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -100),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
if traitCollection.verticalSizeClass == .compact {
finalStack.axis = .horizontal
print("vertical class = compact")
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactContraints)
} else if traitCollection.verticalSizeClass == .regular{
finalStack.axis = .vertical
print("vertical class = regular")
NSLayoutConstraint.deactivate(compactContraints)
NSLayoutConstraint.activate(regularConstraints)
}
}
}
ios swift
add a comment |
up vote
2
down vote
favorite
I have defined four buttons programmatically and added them to UIStackview name 'finalStack'. During rotation I am able to successfully change finalStack orientation but I am unable to move it after adjusting centerY-anchor value. From the console, I have errors stating that I am failing to remove the previous constraints. Is my code to de-activate the constraints incorrect or am I missing something else? The two print statements in my if/else statement tell me that I am correctly hitting the appropriate code block after rotating device.
Simulator is using iPhone XR
In the meantime I'm trying to follow the recommendations and trying to implement symbolic breakpoints but that topic is turning into another major task for me. Would greatly appreciate any insight into either topic. Console Warnings after device rotates
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.red
finalStack.addArrangedSubview(buttonOne)
finalStack.addArrangedSubview(buttonTwo)
finalStack.addArrangedSubview(buttonThree)
finalStack.addArrangedSubview(buttonFour)
view.addSubview(finalStack)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let compactContraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
let regularConstraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -100),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
if traitCollection.verticalSizeClass == .compact {
finalStack.axis = .horizontal
print("vertical class = compact")
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactContraints)
} else if traitCollection.verticalSizeClass == .regular{
finalStack.axis = .vertical
print("vertical class = regular")
NSLayoutConstraint.deactivate(compactContraints)
NSLayoutConstraint.activate(regularConstraints)
}
}
}
ios swift
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have defined four buttons programmatically and added them to UIStackview name 'finalStack'. During rotation I am able to successfully change finalStack orientation but I am unable to move it after adjusting centerY-anchor value. From the console, I have errors stating that I am failing to remove the previous constraints. Is my code to de-activate the constraints incorrect or am I missing something else? The two print statements in my if/else statement tell me that I am correctly hitting the appropriate code block after rotating device.
Simulator is using iPhone XR
In the meantime I'm trying to follow the recommendations and trying to implement symbolic breakpoints but that topic is turning into another major task for me. Would greatly appreciate any insight into either topic. Console Warnings after device rotates
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.red
finalStack.addArrangedSubview(buttonOne)
finalStack.addArrangedSubview(buttonTwo)
finalStack.addArrangedSubview(buttonThree)
finalStack.addArrangedSubview(buttonFour)
view.addSubview(finalStack)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let compactContraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
let regularConstraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -100),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
if traitCollection.verticalSizeClass == .compact {
finalStack.axis = .horizontal
print("vertical class = compact")
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactContraints)
} else if traitCollection.verticalSizeClass == .regular{
finalStack.axis = .vertical
print("vertical class = regular")
NSLayoutConstraint.deactivate(compactContraints)
NSLayoutConstraint.activate(regularConstraints)
}
}
}
ios swift
I have defined four buttons programmatically and added them to UIStackview name 'finalStack'. During rotation I am able to successfully change finalStack orientation but I am unable to move it after adjusting centerY-anchor value. From the console, I have errors stating that I am failing to remove the previous constraints. Is my code to de-activate the constraints incorrect or am I missing something else? The two print statements in my if/else statement tell me that I am correctly hitting the appropriate code block after rotating device.
Simulator is using iPhone XR
In the meantime I'm trying to follow the recommendations and trying to implement symbolic breakpoints but that topic is turning into another major task for me. Would greatly appreciate any insight into either topic. Console Warnings after device rotates
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.red
finalStack.addArrangedSubview(buttonOne)
finalStack.addArrangedSubview(buttonTwo)
finalStack.addArrangedSubview(buttonThree)
finalStack.addArrangedSubview(buttonFour)
view.addSubview(finalStack)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let compactContraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
let regularConstraints = [
finalStack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
finalStack.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -100),
buttonOne.widthAnchor.constraint(equalToConstant: 100),
buttonOne.heightAnchor.constraint(equalToConstant: 100),
buttonTwo.widthAnchor.constraint(equalToConstant: 100),
buttonTwo.heightAnchor.constraint(equalToConstant: 100),
buttonThree.widthAnchor.constraint(equalToConstant: 100),
buttonThree.heightAnchor.constraint(equalToConstant: 100),
buttonFour.widthAnchor.constraint(equalToConstant: 100),
buttonFour.heightAnchor.constraint(equalToConstant: 100),
]
if traitCollection.verticalSizeClass == .compact {
finalStack.axis = .horizontal
print("vertical class = compact")
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactContraints)
} else if traitCollection.verticalSizeClass == .regular{
finalStack.axis = .vertical
print("vertical class = regular")
NSLayoutConstraint.deactivate(compactContraints)
NSLayoutConstraint.activate(regularConstraints)
}
}
}
ios swift
ios swift
asked Nov 11 at 3:31
surnan
115
115
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53245603%2fcompact-regular-size-change-via-rotation-unable-to-simultaneously-satisfy%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