Accessing collectionView cells visible/invisible
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
swift3 uicollectionview swift4 uicollectionviewcell didselectrowatindexpath
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
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
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
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
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
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