How do I simultaneously update the border of a UICollectionViewCell and perform a batch update of...












0















My goal is to add a shadow around the border of a UICollectionView Cell while simultaneously performing a batch update of the UICollectionView, which will then cause the selected cell to expand in height. The idea is that the shadow around the border will fade into view, or come into view immediately as it does in this GIF, but do so following the actual size of the cell as it grows. As shown in the code, I specifically want the shadow to be around the cell and not within the cell itself - this is to maintain the proper boundaries.



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if weekTasks[indexPath.section].count == 0 {
let emptyCell = collectionView.dequeueReusableCell(withReuseIdentifier: "emptyCellID", for: indexPath) as! EmptyCell
return emptyCell
} else {
let assignmentCell = collectionView.dequeueReusableCell(withReuseIdentifier: "assignCellID", for: indexPath) as! AssignmentCell
assignmentCell.myAssignment = weekTasks[indexPath.section][indexPath.item]
assignmentCell.contentView.backgroundColor = UIColor.white
return assignmentCell
}
}

// Sets up size of cell
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if weekTasks[indexPath.section].count == 0 {
return CGSize(width: screenWidth, height: 36 )
} else if (collectionView.indexPathsForSelectedItems?.contains(indexPath))! {
return CGSize(width: screenWidth, height: 110)
} else {
return CGSize(width: screenWidth, height: 46)
}
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 12
cell?.contentView.layer.masksToBounds = true;
cell?.contentView.backgroundColor = UIColor.white

cell?.layer.shadowOffset = CGSize(width: 0 ,height: 1)
cell?.layer.shadowRadius = 4
cell?.layer.shadowOpacity = 0.2

collectionView.performBatchUpdates(nil, completion: { done in
if done {
print("Sweet")
}}
)
}

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 0
cell?.contentView.layer.masksToBounds = true;

cell?.layer.shadowOpacity = 0
}


My CollectionView Cell



class AssignmentCell: UICollectionViewCell, UIGestureRecognizerDelegate {
var heightConstraint: NSLayoutConstraint?

override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}

let helperView = UIView()

func setupViews() {

self.contentView.addSubview(helperView)
let topConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let heightConstraint = helperView.heightAnchor.constraint(equalToConstant: self.frame.height)
helperView.addConstraints([topConstraint, leftConstraint, rightConstraint, heightConstraint])

helperView.addSubview(titleView)
titleView.frame = CGRect(x: 48, y: (self.frame.height / 2) - 10, width: screenWidth - 190, height: 20)

helperView.addSubview(checkboxView)
checkboxView.frame = CGRect(x: 10, y: (self.frame.height / 2) - 9, width: 18, height: 18)
}

func expandCell(to height: CGFloat) {
heightConstraint?.constant = 110

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


}



enter image description here










share|improve this question

























  • Did you try adding layer code inside UIView.animate(withDuration: 0.3, animations: {?

    – DionizB
    Nov 19 '18 at 8:34
















0















My goal is to add a shadow around the border of a UICollectionView Cell while simultaneously performing a batch update of the UICollectionView, which will then cause the selected cell to expand in height. The idea is that the shadow around the border will fade into view, or come into view immediately as it does in this GIF, but do so following the actual size of the cell as it grows. As shown in the code, I specifically want the shadow to be around the cell and not within the cell itself - this is to maintain the proper boundaries.



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if weekTasks[indexPath.section].count == 0 {
let emptyCell = collectionView.dequeueReusableCell(withReuseIdentifier: "emptyCellID", for: indexPath) as! EmptyCell
return emptyCell
} else {
let assignmentCell = collectionView.dequeueReusableCell(withReuseIdentifier: "assignCellID", for: indexPath) as! AssignmentCell
assignmentCell.myAssignment = weekTasks[indexPath.section][indexPath.item]
assignmentCell.contentView.backgroundColor = UIColor.white
return assignmentCell
}
}

// Sets up size of cell
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if weekTasks[indexPath.section].count == 0 {
return CGSize(width: screenWidth, height: 36 )
} else if (collectionView.indexPathsForSelectedItems?.contains(indexPath))! {
return CGSize(width: screenWidth, height: 110)
} else {
return CGSize(width: screenWidth, height: 46)
}
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 12
cell?.contentView.layer.masksToBounds = true;
cell?.contentView.backgroundColor = UIColor.white

cell?.layer.shadowOffset = CGSize(width: 0 ,height: 1)
cell?.layer.shadowRadius = 4
cell?.layer.shadowOpacity = 0.2

collectionView.performBatchUpdates(nil, completion: { done in
if done {
print("Sweet")
}}
)
}

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 0
cell?.contentView.layer.masksToBounds = true;

cell?.layer.shadowOpacity = 0
}


My CollectionView Cell



class AssignmentCell: UICollectionViewCell, UIGestureRecognizerDelegate {
var heightConstraint: NSLayoutConstraint?

override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}

let helperView = UIView()

func setupViews() {

self.contentView.addSubview(helperView)
let topConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let heightConstraint = helperView.heightAnchor.constraint(equalToConstant: self.frame.height)
helperView.addConstraints([topConstraint, leftConstraint, rightConstraint, heightConstraint])

helperView.addSubview(titleView)
titleView.frame = CGRect(x: 48, y: (self.frame.height / 2) - 10, width: screenWidth - 190, height: 20)

helperView.addSubview(checkboxView)
checkboxView.frame = CGRect(x: 10, y: (self.frame.height / 2) - 9, width: 18, height: 18)
}

func expandCell(to height: CGFloat) {
heightConstraint?.constant = 110

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


}



enter image description here










share|improve this question

























  • Did you try adding layer code inside UIView.animate(withDuration: 0.3, animations: {?

    – DionizB
    Nov 19 '18 at 8:34














0












0








0








My goal is to add a shadow around the border of a UICollectionView Cell while simultaneously performing a batch update of the UICollectionView, which will then cause the selected cell to expand in height. The idea is that the shadow around the border will fade into view, or come into view immediately as it does in this GIF, but do so following the actual size of the cell as it grows. As shown in the code, I specifically want the shadow to be around the cell and not within the cell itself - this is to maintain the proper boundaries.



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if weekTasks[indexPath.section].count == 0 {
let emptyCell = collectionView.dequeueReusableCell(withReuseIdentifier: "emptyCellID", for: indexPath) as! EmptyCell
return emptyCell
} else {
let assignmentCell = collectionView.dequeueReusableCell(withReuseIdentifier: "assignCellID", for: indexPath) as! AssignmentCell
assignmentCell.myAssignment = weekTasks[indexPath.section][indexPath.item]
assignmentCell.contentView.backgroundColor = UIColor.white
return assignmentCell
}
}

// Sets up size of cell
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if weekTasks[indexPath.section].count == 0 {
return CGSize(width: screenWidth, height: 36 )
} else if (collectionView.indexPathsForSelectedItems?.contains(indexPath))! {
return CGSize(width: screenWidth, height: 110)
} else {
return CGSize(width: screenWidth, height: 46)
}
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 12
cell?.contentView.layer.masksToBounds = true;
cell?.contentView.backgroundColor = UIColor.white

cell?.layer.shadowOffset = CGSize(width: 0 ,height: 1)
cell?.layer.shadowRadius = 4
cell?.layer.shadowOpacity = 0.2

collectionView.performBatchUpdates(nil, completion: { done in
if done {
print("Sweet")
}}
)
}

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 0
cell?.contentView.layer.masksToBounds = true;

cell?.layer.shadowOpacity = 0
}


My CollectionView Cell



class AssignmentCell: UICollectionViewCell, UIGestureRecognizerDelegate {
var heightConstraint: NSLayoutConstraint?

override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}

let helperView = UIView()

func setupViews() {

self.contentView.addSubview(helperView)
let topConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let heightConstraint = helperView.heightAnchor.constraint(equalToConstant: self.frame.height)
helperView.addConstraints([topConstraint, leftConstraint, rightConstraint, heightConstraint])

helperView.addSubview(titleView)
titleView.frame = CGRect(x: 48, y: (self.frame.height / 2) - 10, width: screenWidth - 190, height: 20)

helperView.addSubview(checkboxView)
checkboxView.frame = CGRect(x: 10, y: (self.frame.height / 2) - 9, width: 18, height: 18)
}

func expandCell(to height: CGFloat) {
heightConstraint?.constant = 110

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


}



enter image description here










share|improve this question
















My goal is to add a shadow around the border of a UICollectionView Cell while simultaneously performing a batch update of the UICollectionView, which will then cause the selected cell to expand in height. The idea is that the shadow around the border will fade into view, or come into view immediately as it does in this GIF, but do so following the actual size of the cell as it grows. As shown in the code, I specifically want the shadow to be around the cell and not within the cell itself - this is to maintain the proper boundaries.



override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if weekTasks[indexPath.section].count == 0 {
let emptyCell = collectionView.dequeueReusableCell(withReuseIdentifier: "emptyCellID", for: indexPath) as! EmptyCell
return emptyCell
} else {
let assignmentCell = collectionView.dequeueReusableCell(withReuseIdentifier: "assignCellID", for: indexPath) as! AssignmentCell
assignmentCell.myAssignment = weekTasks[indexPath.section][indexPath.item]
assignmentCell.contentView.backgroundColor = UIColor.white
return assignmentCell
}
}

// Sets up size of cell
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if weekTasks[indexPath.section].count == 0 {
return CGSize(width: screenWidth, height: 36 )
} else if (collectionView.indexPathsForSelectedItems?.contains(indexPath))! {
return CGSize(width: screenWidth, height: 110)
} else {
return CGSize(width: screenWidth, height: 46)
}
}

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 12
cell?.contentView.layer.masksToBounds = true;
cell?.contentView.backgroundColor = UIColor.white

cell?.layer.shadowOffset = CGSize(width: 0 ,height: 1)
cell?.layer.shadowRadius = 4
cell?.layer.shadowOpacity = 0.2

collectionView.performBatchUpdates(nil, completion: { done in
if done {
print("Sweet")
}}
)
}

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.contentView.layer.cornerRadius = 0
cell?.contentView.layer.masksToBounds = true;

cell?.layer.shadowOpacity = 0
}


My CollectionView Cell



class AssignmentCell: UICollectionViewCell, UIGestureRecognizerDelegate {
var heightConstraint: NSLayoutConstraint?

override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}

let helperView = UIView()

func setupViews() {

self.contentView.addSubview(helperView)
let topConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.left, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.left, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.right, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: helperView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: superview, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let heightConstraint = helperView.heightAnchor.constraint(equalToConstant: self.frame.height)
helperView.addConstraints([topConstraint, leftConstraint, rightConstraint, heightConstraint])

helperView.addSubview(titleView)
titleView.frame = CGRect(x: 48, y: (self.frame.height / 2) - 10, width: screenWidth - 190, height: 20)

helperView.addSubview(checkboxView)
checkboxView.frame = CGRect(x: 10, y: (self.frame.height / 2) - 9, width: 18, height: 18)
}

func expandCell(to height: CGFloat) {
heightConstraint?.constant = 110

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


}



enter image description here







swift uicollectionview uicollectionviewcell performbatchupdates






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 22:42







Carter Foughty

















asked Nov 19 '18 at 6:33









Carter FoughtyCarter Foughty

135




135













  • Did you try adding layer code inside UIView.animate(withDuration: 0.3, animations: {?

    – DionizB
    Nov 19 '18 at 8:34



















  • Did you try adding layer code inside UIView.animate(withDuration: 0.3, animations: {?

    – DionizB
    Nov 19 '18 at 8:34

















Did you try adding layer code inside UIView.animate(withDuration: 0.3, animations: {?

– DionizB
Nov 19 '18 at 8:34





Did you try adding layer code inside UIView.animate(withDuration: 0.3, animations: {?

– DionizB
Nov 19 '18 at 8:34












1 Answer
1






active

oldest

votes


















0














It actually follows the cell size. You get that effect because you are setting a fixed cell height and animating the layout change after. You can try to set cell size automatic (only for the expanded one).



In your cell, create a method to animate the size from current value to x (110 in your case).



Add a constraint to be equal to the height of you container and do smth like this:



func expandCell(to height: CGFloat) {
self.cellHeightConstraint?.constant = height

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


// edit



Add a new UIView in your ContentView and in that put all your other views. Set top, bottom, left, right of that view to 0, to its superview(contentView) and a height constraint on that view with @999 priority. See below image:



enter image description here






share|improve this answer


























  • Thanks for the help! How exactly, and where, would I add the cell height constraint?

    – Carter Foughty
    Nov 19 '18 at 16:15











  • see my edited post

    – Deryck Lucian
    Nov 19 '18 at 16:33











  • Unfortunately, I can't quite figure out what you're getting at. I've tried setting the constraints (although programmatically, as I'm not using the storyboard), but I get thrown errors. Any tips? Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIView: 0x7ff29845e9d0; frame = (0 0; 0 0); layer = <CALayer: 0x600000ad0880>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.'

    – Carter Foughty
    Nov 19 '18 at 17:47













  • You created the cell layout programatically? post the code you are using to create that constaint.

    – Deryck Lucian
    Nov 19 '18 at 17:51













  • Added them inn my edited post!

    – Carter Foughty
    Nov 19 '18 at 22:42











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369424%2fhow-do-i-simultaneously-update-the-border-of-a-uicollectionviewcell-and-perform%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









0














It actually follows the cell size. You get that effect because you are setting a fixed cell height and animating the layout change after. You can try to set cell size automatic (only for the expanded one).



In your cell, create a method to animate the size from current value to x (110 in your case).



Add a constraint to be equal to the height of you container and do smth like this:



func expandCell(to height: CGFloat) {
self.cellHeightConstraint?.constant = height

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


// edit



Add a new UIView in your ContentView and in that put all your other views. Set top, bottom, left, right of that view to 0, to its superview(contentView) and a height constraint on that view with @999 priority. See below image:



enter image description here






share|improve this answer


























  • Thanks for the help! How exactly, and where, would I add the cell height constraint?

    – Carter Foughty
    Nov 19 '18 at 16:15











  • see my edited post

    – Deryck Lucian
    Nov 19 '18 at 16:33











  • Unfortunately, I can't quite figure out what you're getting at. I've tried setting the constraints (although programmatically, as I'm not using the storyboard), but I get thrown errors. Any tips? Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIView: 0x7ff29845e9d0; frame = (0 0; 0 0); layer = <CALayer: 0x600000ad0880>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.'

    – Carter Foughty
    Nov 19 '18 at 17:47













  • You created the cell layout programatically? post the code you are using to create that constaint.

    – Deryck Lucian
    Nov 19 '18 at 17:51













  • Added them inn my edited post!

    – Carter Foughty
    Nov 19 '18 at 22:42
















0














It actually follows the cell size. You get that effect because you are setting a fixed cell height and animating the layout change after. You can try to set cell size automatic (only for the expanded one).



In your cell, create a method to animate the size from current value to x (110 in your case).



Add a constraint to be equal to the height of you container and do smth like this:



func expandCell(to height: CGFloat) {
self.cellHeightConstraint?.constant = height

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


// edit



Add a new UIView in your ContentView and in that put all your other views. Set top, bottom, left, right of that view to 0, to its superview(contentView) and a height constraint on that view with @999 priority. See below image:



enter image description here






share|improve this answer


























  • Thanks for the help! How exactly, and where, would I add the cell height constraint?

    – Carter Foughty
    Nov 19 '18 at 16:15











  • see my edited post

    – Deryck Lucian
    Nov 19 '18 at 16:33











  • Unfortunately, I can't quite figure out what you're getting at. I've tried setting the constraints (although programmatically, as I'm not using the storyboard), but I get thrown errors. Any tips? Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIView: 0x7ff29845e9d0; frame = (0 0; 0 0); layer = <CALayer: 0x600000ad0880>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.'

    – Carter Foughty
    Nov 19 '18 at 17:47













  • You created the cell layout programatically? post the code you are using to create that constaint.

    – Deryck Lucian
    Nov 19 '18 at 17:51













  • Added them inn my edited post!

    – Carter Foughty
    Nov 19 '18 at 22:42














0












0








0







It actually follows the cell size. You get that effect because you are setting a fixed cell height and animating the layout change after. You can try to set cell size automatic (only for the expanded one).



In your cell, create a method to animate the size from current value to x (110 in your case).



Add a constraint to be equal to the height of you container and do smth like this:



func expandCell(to height: CGFloat) {
self.cellHeightConstraint?.constant = height

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


// edit



Add a new UIView in your ContentView and in that put all your other views. Set top, bottom, left, right of that view to 0, to its superview(contentView) and a height constraint on that view with @999 priority. See below image:



enter image description here






share|improve this answer















It actually follows the cell size. You get that effect because you are setting a fixed cell height and animating the layout change after. You can try to set cell size automatic (only for the expanded one).



In your cell, create a method to animate the size from current value to x (110 in your case).



Add a constraint to be equal to the height of you container and do smth like this:



func expandCell(to height: CGFloat) {
self.cellHeightConstraint?.constant = height

UIView.animate(withDuration: 0.3, animations: {
self.layoutIfNeeded()
}) { (completed) in
}
}


// edit



Add a new UIView in your ContentView and in that put all your other views. Set top, bottom, left, right of that view to 0, to its superview(contentView) and a height constraint on that view with @999 priority. See below image:



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 16:33

























answered Nov 19 '18 at 11:43









Deryck LucianDeryck Lucian

1538




1538













  • Thanks for the help! How exactly, and where, would I add the cell height constraint?

    – Carter Foughty
    Nov 19 '18 at 16:15











  • see my edited post

    – Deryck Lucian
    Nov 19 '18 at 16:33











  • Unfortunately, I can't quite figure out what you're getting at. I've tried setting the constraints (although programmatically, as I'm not using the storyboard), but I get thrown errors. Any tips? Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIView: 0x7ff29845e9d0; frame = (0 0; 0 0); layer = <CALayer: 0x600000ad0880>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.'

    – Carter Foughty
    Nov 19 '18 at 17:47













  • You created the cell layout programatically? post the code you are using to create that constaint.

    – Deryck Lucian
    Nov 19 '18 at 17:51













  • Added them inn my edited post!

    – Carter Foughty
    Nov 19 '18 at 22:42



















  • Thanks for the help! How exactly, and where, would I add the cell height constraint?

    – Carter Foughty
    Nov 19 '18 at 16:15











  • see my edited post

    – Deryck Lucian
    Nov 19 '18 at 16:33











  • Unfortunately, I can't quite figure out what you're getting at. I've tried setting the constraints (although programmatically, as I'm not using the storyboard), but I get thrown errors. Any tips? Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIView: 0x7ff29845e9d0; frame = (0 0; 0 0); layer = <CALayer: 0x600000ad0880>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.'

    – Carter Foughty
    Nov 19 '18 at 17:47













  • You created the cell layout programatically? post the code you are using to create that constaint.

    – Deryck Lucian
    Nov 19 '18 at 17:51













  • Added them inn my edited post!

    – Carter Foughty
    Nov 19 '18 at 22:42

















Thanks for the help! How exactly, and where, would I add the cell height constraint?

– Carter Foughty
Nov 19 '18 at 16:15





Thanks for the help! How exactly, and where, would I add the cell height constraint?

– Carter Foughty
Nov 19 '18 at 16:15













see my edited post

– Deryck Lucian
Nov 19 '18 at 16:33





see my edited post

– Deryck Lucian
Nov 19 '18 at 16:33













Unfortunately, I can't quite figure out what you're getting at. I've tried setting the constraints (although programmatically, as I'm not using the storyboard), but I get thrown errors. Any tips? Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIView: 0x7ff29845e9d0; frame = (0 0; 0 0); layer = <CALayer: 0x600000ad0880>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.'

– Carter Foughty
Nov 19 '18 at 17:47







Unfortunately, I can't quite figure out what you're getting at. I've tried setting the constraints (although programmatically, as I'm not using the storyboard), but I get thrown errors. Any tips? Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIView: 0x7ff29845e9d0; frame = (0 0; 0 0); layer = <CALayer: 0x600000ad0880>>: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.'

– Carter Foughty
Nov 19 '18 at 17:47















You created the cell layout programatically? post the code you are using to create that constaint.

– Deryck Lucian
Nov 19 '18 at 17:51







You created the cell layout programatically? post the code you are using to create that constaint.

– Deryck Lucian
Nov 19 '18 at 17:51















Added them inn my edited post!

– Carter Foughty
Nov 19 '18 at 22:42





Added them inn my edited post!

– Carter Foughty
Nov 19 '18 at 22:42


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369424%2fhow-do-i-simultaneously-update-the-border-of-a-uicollectionviewcell-and-perform%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?