Tableview change constraints to full screen when switch to landscape
Basically, I have a tableview and when I switch to landscape I want it to set the table view to fullscreen and when I switch it back to portrait, it should revert to default constraints. It works if I remove the breakpoint.
However, when I switch it back from landscape to portrait, it does not return to default. When I switch it back to portrait, I am editing the constraints for it to do what I want. However, I am open to other solutions. Please advise me on what I should do. I added the breakpoint using UIViewAlertForUnsatisfiableConstraints
just like this image:
override func viewDidLoad() {
super.viewDidLoad()
parseData(noOfPosts:90)
TableView.delegate = self
TableView.dataSource = self
TableView.tableFooterView = UIView()
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
myTop2Constraint.isActive = true
myBtm2Constraint.isActive = true
if(UIDevice.current.orientation.isLandscape){
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
}
}
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
let myTopConstraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0)
let myBtmConstraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0)
myTopConstraint.isActive = false
myBtmConstraint.isActive = false
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
if(UIDevice.current.orientation.isLandscape){
self.catIsuSemasa.isHidden = true
self.catOthers.isHidden = true
self.catSocial.isHidden = true
self.catPolitics.isHidden = true
if(myTop2Constraint.isActive){
print("error1?")
myTop2Constraint.isActive = false
print("error2?")
myBtm2Constraint.isActive = false
print("error3?")
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}else{
TableView.removeAllConstraints()
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}
}else{
self.catIsuSemasa.isHidden = false
self.catOthers.isHidden = false
self.catSocial.isHidden = false
self.catPolitics.isHidden = false
if(myTopConstraint.isActive){
print("error")
myTopConstraint.isActive = false
print("error2")
myBtmConstraint.isActive = false
print("error3")
myTop2Constraint.isActive = true
print("error4")
myBtm2Constraint.isActive = true
print("run?")
}
}
}
extension UIView {
func removeAllConstraints() {
self.removeConstraints(self.constraints)
for view in self.subviews {
view.removeAllConstraints()
}
}
}
ios swift uitableview view constraints
add a comment |
Basically, I have a tableview and when I switch to landscape I want it to set the table view to fullscreen and when I switch it back to portrait, it should revert to default constraints. It works if I remove the breakpoint.
However, when I switch it back from landscape to portrait, it does not return to default. When I switch it back to portrait, I am editing the constraints for it to do what I want. However, I am open to other solutions. Please advise me on what I should do. I added the breakpoint using UIViewAlertForUnsatisfiableConstraints
just like this image:
override func viewDidLoad() {
super.viewDidLoad()
parseData(noOfPosts:90)
TableView.delegate = self
TableView.dataSource = self
TableView.tableFooterView = UIView()
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
myTop2Constraint.isActive = true
myBtm2Constraint.isActive = true
if(UIDevice.current.orientation.isLandscape){
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
}
}
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
let myTopConstraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0)
let myBtmConstraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0)
myTopConstraint.isActive = false
myBtmConstraint.isActive = false
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
if(UIDevice.current.orientation.isLandscape){
self.catIsuSemasa.isHidden = true
self.catOthers.isHidden = true
self.catSocial.isHidden = true
self.catPolitics.isHidden = true
if(myTop2Constraint.isActive){
print("error1?")
myTop2Constraint.isActive = false
print("error2?")
myBtm2Constraint.isActive = false
print("error3?")
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}else{
TableView.removeAllConstraints()
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}
}else{
self.catIsuSemasa.isHidden = false
self.catOthers.isHidden = false
self.catSocial.isHidden = false
self.catPolitics.isHidden = false
if(myTopConstraint.isActive){
print("error")
myTopConstraint.isActive = false
print("error2")
myBtmConstraint.isActive = false
print("error3")
myTop2Constraint.isActive = true
print("error4")
myBtm2Constraint.isActive = true
print("run?")
}
}
}
extension UIView {
func removeAllConstraints() {
self.removeConstraints(self.constraints)
for view in self.subviews {
view.removeAllConstraints()
}
}
}
ios swift uitableview view constraints
why you are set constrain programmatically you can do this same by storyboard using size class (vary for traits)?. this link might be help you to set different constrain for landscape and portrait in storyboard.
– Jatin Kathrotiya
Nov 22 '18 at 4:15
I am looking into it now, thanks for the pointer
– Zack Cheang Weng Seong
Nov 22 '18 at 4:24
@JatinKathrotiya hey, thanks for pointing me in the right direction, I manage to use the vary for traits solution to fix my problem. If you post it it the answer's comment, ill make it a solution
– Zack Cheang Weng Seong
Nov 22 '18 at 5:18
Most Welcome , I added as answer so it will help full to other user
– Jatin Kathrotiya
Nov 22 '18 at 5:33
add a comment |
Basically, I have a tableview and when I switch to landscape I want it to set the table view to fullscreen and when I switch it back to portrait, it should revert to default constraints. It works if I remove the breakpoint.
However, when I switch it back from landscape to portrait, it does not return to default. When I switch it back to portrait, I am editing the constraints for it to do what I want. However, I am open to other solutions. Please advise me on what I should do. I added the breakpoint using UIViewAlertForUnsatisfiableConstraints
just like this image:
override func viewDidLoad() {
super.viewDidLoad()
parseData(noOfPosts:90)
TableView.delegate = self
TableView.dataSource = self
TableView.tableFooterView = UIView()
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
myTop2Constraint.isActive = true
myBtm2Constraint.isActive = true
if(UIDevice.current.orientation.isLandscape){
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
}
}
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
let myTopConstraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0)
let myBtmConstraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0)
myTopConstraint.isActive = false
myBtmConstraint.isActive = false
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
if(UIDevice.current.orientation.isLandscape){
self.catIsuSemasa.isHidden = true
self.catOthers.isHidden = true
self.catSocial.isHidden = true
self.catPolitics.isHidden = true
if(myTop2Constraint.isActive){
print("error1?")
myTop2Constraint.isActive = false
print("error2?")
myBtm2Constraint.isActive = false
print("error3?")
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}else{
TableView.removeAllConstraints()
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}
}else{
self.catIsuSemasa.isHidden = false
self.catOthers.isHidden = false
self.catSocial.isHidden = false
self.catPolitics.isHidden = false
if(myTopConstraint.isActive){
print("error")
myTopConstraint.isActive = false
print("error2")
myBtmConstraint.isActive = false
print("error3")
myTop2Constraint.isActive = true
print("error4")
myBtm2Constraint.isActive = true
print("run?")
}
}
}
extension UIView {
func removeAllConstraints() {
self.removeConstraints(self.constraints)
for view in self.subviews {
view.removeAllConstraints()
}
}
}
ios swift uitableview view constraints
Basically, I have a tableview and when I switch to landscape I want it to set the table view to fullscreen and when I switch it back to portrait, it should revert to default constraints. It works if I remove the breakpoint.
However, when I switch it back from landscape to portrait, it does not return to default. When I switch it back to portrait, I am editing the constraints for it to do what I want. However, I am open to other solutions. Please advise me on what I should do. I added the breakpoint using UIViewAlertForUnsatisfiableConstraints
just like this image:
override func viewDidLoad() {
super.viewDidLoad()
parseData(noOfPosts:90)
TableView.delegate = self
TableView.dataSource = self
TableView.tableFooterView = UIView()
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
myTop2Constraint.isActive = true
myBtm2Constraint.isActive = true
if(UIDevice.current.orientation.isLandscape){
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
}
}
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
let myTop2Constraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50)
let myBtm2Constraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 50)
let myTopConstraint:NSLayoutConstraint = TableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0)
let myBtmConstraint:NSLayoutConstraint = TableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0)
myTopConstraint.isActive = false
myBtmConstraint.isActive = false
myTop2Constraint.isActive = false
myBtm2Constraint.isActive = false
if(UIDevice.current.orientation.isLandscape){
self.catIsuSemasa.isHidden = true
self.catOthers.isHidden = true
self.catSocial.isHidden = true
self.catPolitics.isHidden = true
if(myTop2Constraint.isActive){
print("error1?")
myTop2Constraint.isActive = false
print("error2?")
myBtm2Constraint.isActive = false
print("error3?")
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}else{
TableView.removeAllConstraints()
myTopConstraint.isActive = true
myBtmConstraint.isActive = true
}
}else{
self.catIsuSemasa.isHidden = false
self.catOthers.isHidden = false
self.catSocial.isHidden = false
self.catPolitics.isHidden = false
if(myTopConstraint.isActive){
print("error")
myTopConstraint.isActive = false
print("error2")
myBtmConstraint.isActive = false
print("error3")
myTop2Constraint.isActive = true
print("error4")
myBtm2Constraint.isActive = true
print("run?")
}
}
}
extension UIView {
func removeAllConstraints() {
self.removeConstraints(self.constraints)
for view in self.subviews {
view.removeAllConstraints()
}
}
}
ios swift uitableview view constraints
ios swift uitableview view constraints
edited Nov 22 '18 at 5:17
kit
1,1063716
1,1063716
asked Nov 22 '18 at 4:02
Zack Cheang Weng SeongZack Cheang Weng Seong
459
459
why you are set constrain programmatically you can do this same by storyboard using size class (vary for traits)?. this link might be help you to set different constrain for landscape and portrait in storyboard.
– Jatin Kathrotiya
Nov 22 '18 at 4:15
I am looking into it now, thanks for the pointer
– Zack Cheang Weng Seong
Nov 22 '18 at 4:24
@JatinKathrotiya hey, thanks for pointing me in the right direction, I manage to use the vary for traits solution to fix my problem. If you post it it the answer's comment, ill make it a solution
– Zack Cheang Weng Seong
Nov 22 '18 at 5:18
Most Welcome , I added as answer so it will help full to other user
– Jatin Kathrotiya
Nov 22 '18 at 5:33
add a comment |
why you are set constrain programmatically you can do this same by storyboard using size class (vary for traits)?. this link might be help you to set different constrain for landscape and portrait in storyboard.
– Jatin Kathrotiya
Nov 22 '18 at 4:15
I am looking into it now, thanks for the pointer
– Zack Cheang Weng Seong
Nov 22 '18 at 4:24
@JatinKathrotiya hey, thanks for pointing me in the right direction, I manage to use the vary for traits solution to fix my problem. If you post it it the answer's comment, ill make it a solution
– Zack Cheang Weng Seong
Nov 22 '18 at 5:18
Most Welcome , I added as answer so it will help full to other user
– Jatin Kathrotiya
Nov 22 '18 at 5:33
why you are set constrain programmatically you can do this same by storyboard using size class (vary for traits)?. this link might be help you to set different constrain for landscape and portrait in storyboard.
– Jatin Kathrotiya
Nov 22 '18 at 4:15
why you are set constrain programmatically you can do this same by storyboard using size class (vary for traits)?. this link might be help you to set different constrain for landscape and portrait in storyboard.
– Jatin Kathrotiya
Nov 22 '18 at 4:15
I am looking into it now, thanks for the pointer
– Zack Cheang Weng Seong
Nov 22 '18 at 4:24
I am looking into it now, thanks for the pointer
– Zack Cheang Weng Seong
Nov 22 '18 at 4:24
@JatinKathrotiya hey, thanks for pointing me in the right direction, I manage to use the vary for traits solution to fix my problem. If you post it it the answer's comment, ill make it a solution
– Zack Cheang Weng Seong
Nov 22 '18 at 5:18
@JatinKathrotiya hey, thanks for pointing me in the right direction, I manage to use the vary for traits solution to fix my problem. If you post it it the answer's comment, ill make it a solution
– Zack Cheang Weng Seong
Nov 22 '18 at 5:18
Most Welcome , I added as answer so it will help full to other user
– Jatin Kathrotiya
Nov 22 '18 at 5:33
Most Welcome , I added as answer so it will help full to other user
– Jatin Kathrotiya
Nov 22 '18 at 5:33
add a comment |
1 Answer
1
active
oldest
votes
App support landscape and portrait then we do not required set constrain programatically we can achieve same thing by using storyboard's size class (vary for traits). By using size class we can create adaptive layout design. we can set different constrain for landscape and portrait app.
Please check below tutorial link :
Tutorial Link
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%2f53423700%2ftableview-change-constraints-to-full-screen-when-switch-to-landscape%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
App support landscape and portrait then we do not required set constrain programatically we can achieve same thing by using storyboard's size class (vary for traits). By using size class we can create adaptive layout design. we can set different constrain for landscape and portrait app.
Please check below tutorial link :
Tutorial Link
add a comment |
App support landscape and portrait then we do not required set constrain programatically we can achieve same thing by using storyboard's size class (vary for traits). By using size class we can create adaptive layout design. we can set different constrain for landscape and portrait app.
Please check below tutorial link :
Tutorial Link
add a comment |
App support landscape and portrait then we do not required set constrain programatically we can achieve same thing by using storyboard's size class (vary for traits). By using size class we can create adaptive layout design. we can set different constrain for landscape and portrait app.
Please check below tutorial link :
Tutorial Link
App support landscape and portrait then we do not required set constrain programatically we can achieve same thing by using storyboard's size class (vary for traits). By using size class we can create adaptive layout design. we can set different constrain for landscape and portrait app.
Please check below tutorial link :
Tutorial Link
answered Nov 22 '18 at 5:31
Jatin KathrotiyaJatin Kathrotiya
419210
419210
add a comment |
add a comment |
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%2f53423700%2ftableview-change-constraints-to-full-screen-when-switch-to-landscape%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 you are set constrain programmatically you can do this same by storyboard using size class (vary for traits)?. this link might be help you to set different constrain for landscape and portrait in storyboard.
– Jatin Kathrotiya
Nov 22 '18 at 4:15
I am looking into it now, thanks for the pointer
– Zack Cheang Weng Seong
Nov 22 '18 at 4:24
@JatinKathrotiya hey, thanks for pointing me in the right direction, I manage to use the vary for traits solution to fix my problem. If you post it it the answer's comment, ill make it a solution
– Zack Cheang Weng Seong
Nov 22 '18 at 5:18
Most Welcome , I added as answer so it will help full to other user
– Jatin Kathrotiya
Nov 22 '18 at 5:33