Accessing collectionView cells visible/invisible









up vote
0
down vote

favorite
1












I got a function to flip my collection view cells, which is working fine. My problem is that I want to flip all the cells and not just this one visible cell, so when I swipe to next cell it will be flipped.



This is what I am using to flip the one visible cell only. Any help in the right direction would be appreciated.



func flipAction() 
let visibleRect = CGRect(origin: mainCollecView.contentOffset, size: mainCollecView.bounds.size)
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
let visibleIndexPath = mainCollecView.indexPathForItem(at: visiblePoint)
let cell = mainCollecView.cellForItem(at: visibleIndexPath!) as! MainCollectionViewCell

if cell.isFlipped == false
//Flip card
cell.flip()
cell.isFlipped = true
flipBtn.setImage(UIImage(named: "reversed"), for: .normal)

else
// Flip the card back
flipBtn.setImage(UIImage(named: "Calendar"), for: .normal)
cell.flipBack()
cell.isFlipped = false











share|improve this question





















  • Complete an array form all cells with like var myarr = Array<Bool> for isFlipped values. Then if myarr[indexPath ... ] cell...
    – user3344236
    2 days ago










  • @user3344236, thanks for your response. I am new to swift, can you give an example please... Thank you
    – Iam Wayne
    2 days ago














up vote
0
down vote

favorite
1












I got a function to flip my collection view cells, which is working fine. My problem is that I want to flip all the cells and not just this one visible cell, so when I swipe to next cell it will be flipped.



This is what I am using to flip the one visible cell only. Any help in the right direction would be appreciated.



func flipAction() 
let visibleRect = CGRect(origin: mainCollecView.contentOffset, size: mainCollecView.bounds.size)
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
let visibleIndexPath = mainCollecView.indexPathForItem(at: visiblePoint)
let cell = mainCollecView.cellForItem(at: visibleIndexPath!) as! MainCollectionViewCell

if cell.isFlipped == false
//Flip card
cell.flip()
cell.isFlipped = true
flipBtn.setImage(UIImage(named: "reversed"), for: .normal)

else
// Flip the card back
flipBtn.setImage(UIImage(named: "Calendar"), for: .normal)
cell.flipBack()
cell.isFlipped = false











share|improve this question





















  • Complete an array form all cells with like var myarr = Array<Bool> for isFlipped values. Then if myarr[indexPath ... ] cell...
    – user3344236
    2 days ago










  • @user3344236, thanks for your response. I am new to swift, can you give an example please... Thank you
    – Iam Wayne
    2 days ago












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I got a function to flip my collection view cells, which is working fine. My problem is that I want to flip all the cells and not just this one visible cell, so when I swipe to next cell it will be flipped.



This is what I am using to flip the one visible cell only. Any help in the right direction would be appreciated.



func flipAction() 
let visibleRect = CGRect(origin: mainCollecView.contentOffset, size: mainCollecView.bounds.size)
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
let visibleIndexPath = mainCollecView.indexPathForItem(at: visiblePoint)
let cell = mainCollecView.cellForItem(at: visibleIndexPath!) as! MainCollectionViewCell

if cell.isFlipped == false
//Flip card
cell.flip()
cell.isFlipped = true
flipBtn.setImage(UIImage(named: "reversed"), for: .normal)

else
// Flip the card back
flipBtn.setImage(UIImage(named: "Calendar"), for: .normal)
cell.flipBack()
cell.isFlipped = false











share|improve this question













I got a function to flip my collection view cells, which is working fine. My problem is that I want to flip all the cells and not just this one visible cell, so when I swipe to next cell it will be flipped.



This is what I am using to flip the one visible cell only. Any help in the right direction would be appreciated.



func flipAction() 
let visibleRect = CGRect(origin: mainCollecView.contentOffset, size: mainCollecView.bounds.size)
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
let visibleIndexPath = mainCollecView.indexPathForItem(at: visiblePoint)
let cell = mainCollecView.cellForItem(at: visibleIndexPath!) as! MainCollectionViewCell

if cell.isFlipped == false
//Flip card
cell.flip()
cell.isFlipped = true
flipBtn.setImage(UIImage(named: "reversed"), for: .normal)

else
// Flip the card back
flipBtn.setImage(UIImage(named: "Calendar"), for: .normal)
cell.flipBack()
cell.isFlipped = false








swift3 uicollectionview swift4 uicollectionviewcell didselectrowatindexpath






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 6 at 6:53









Iam Wayne

114111




114111











  • Complete an array form all cells with like var myarr = Array<Bool> for isFlipped values. Then if myarr[indexPath ... ] cell...
    – user3344236
    2 days ago










  • @user3344236, thanks for your response. I am new to swift, can you give an example please... Thank you
    – Iam Wayne
    2 days ago
















  • Complete an array form all cells with like var myarr = Array<Bool> for isFlipped values. Then if myarr[indexPath ... ] cell...
    – user3344236
    2 days ago










  • @user3344236, thanks for your response. I am new to swift, can you give an example please... Thank you
    – Iam Wayne
    2 days ago















Complete an array form all cells with like var myarr = Array<Bool> for isFlipped values. Then if myarr[indexPath ... ] cell...
– user3344236
2 days ago




Complete an array form all cells with like var myarr = Array<Bool> for isFlipped values. Then if myarr[indexPath ... ] cell...
– user3344236
2 days ago












@user3344236, thanks for your response. I am new to swift, can you give an example please... Thank you
– Iam Wayne
2 days ago




@user3344236, thanks for your response. I am new to swift, can you give an example please... Thank you
– Iam Wayne
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













You can use different approaches. But if you want all to be flipped, use a variable in you Class, like



 var isFlipped:Bool = false 


Inside your function now:



 flipAction() 
isfliped = !isfliped
mycollection.reload() //where mycollection is yours



Then inside your



 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
if isfliped == false
// your code for cell when is not flipped
else
//your code for cell when is flipped



This way all cells will be flipped or not at once, not depending if they are visible or not.






share|improve this answer




















  • thanks for your response. You solution wont work, because I am using the flip method inside a button and not the collectionViewcellForItemAt.
    – Iam Wayne
    yesterday










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',
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%2f53167016%2faccessing-collectionview-cells-visible-invisible%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You can use different approaches. But if you want all to be flipped, use a variable in you Class, like



 var isFlipped:Bool = false 


Inside your function now:



 flipAction() 
isfliped = !isfliped
mycollection.reload() //where mycollection is yours



Then inside your



 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
if isfliped == false
// your code for cell when is not flipped
else
//your code for cell when is flipped



This way all cells will be flipped or not at once, not depending if they are visible or not.






share|improve this answer




















  • thanks for your response. You solution wont work, because I am using the flip method inside a button and not the collectionViewcellForItemAt.
    – Iam Wayne
    yesterday














up vote
0
down vote













You can use different approaches. But if you want all to be flipped, use a variable in you Class, like



 var isFlipped:Bool = false 


Inside your function now:



 flipAction() 
isfliped = !isfliped
mycollection.reload() //where mycollection is yours



Then inside your



 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
if isfliped == false
// your code for cell when is not flipped
else
//your code for cell when is flipped



This way all cells will be flipped or not at once, not depending if they are visible or not.






share|improve this answer




















  • thanks for your response. You solution wont work, because I am using the flip method inside a button and not the collectionViewcellForItemAt.
    – Iam Wayne
    yesterday












up vote
0
down vote










up vote
0
down vote









You can use different approaches. But if you want all to be flipped, use a variable in you Class, like



 var isFlipped:Bool = false 


Inside your function now:



 flipAction() 
isfliped = !isfliped
mycollection.reload() //where mycollection is yours



Then inside your



 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
if isfliped == false
// your code for cell when is not flipped
else
//your code for cell when is flipped



This way all cells will be flipped or not at once, not depending if they are visible or not.






share|improve this answer












You can use different approaches. But if you want all to be flipped, use a variable in you Class, like



 var isFlipped:Bool = false 


Inside your function now:



 flipAction() 
isfliped = !isfliped
mycollection.reload() //where mycollection is yours



Then inside your



 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
if isfliped == false
// your code for cell when is not flipped
else
//your code for cell when is flipped



This way all cells will be flipped or not at once, not depending if they are visible or not.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









user3344236

2,64711319




2,64711319











  • thanks for your response. You solution wont work, because I am using the flip method inside a button and not the collectionViewcellForItemAt.
    – Iam Wayne
    yesterday
















  • thanks for your response. You solution wont work, because I am using the flip method inside a button and not the collectionViewcellForItemAt.
    – Iam Wayne
    yesterday















thanks for your response. You solution wont work, because I am using the flip method inside a button and not the collectionViewcellForItemAt.
– Iam Wayne
yesterday




thanks for your response. You solution wont work, because I am using the flip method inside a button and not the collectionViewcellForItemAt.
– Iam Wayne
yesterday

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53167016%2faccessing-collectionview-cells-visible-invisible%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus