UICollectionView | simple pinterest like layout using UICollectionView | Grid library
kandi X-RAY | UICollectionView Summary
kandi X-RAY | UICollectionView Summary
A simple pinterest like layout using UICollectionView and UICollectionViewFlow Layout
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of UICollectionView
UICollectionView Key Features
UICollectionView Examples and Code Snippets
Community Discussions
Trending Discussions on UICollectionView
QUESTION
I am trying to create custom segment control using CollectionViewCell. So i can manage text size of the segment control in different devices. But it is not working properly in all the devices.
I have taken one cell inside collection view and used sizeForItemAt
delegate method to equally set the cells. There will be only 3 cells. That is shown in the image.
This is the code for sizeForItemAt
ANSWER
Answered 2022-Mar-22 at 12:10lbl_name.adjustsFontSizeToFitWidth = true
QUESTION
Basically what I am trying to do is cache the cell and have the video keep playing. When the user scroll back to the cell, the video should just show from where it was playing.
The problem is that the player gets removed and the cell ends up on a random cell instead of its designated area.
You will need to have two videos for this to work, I downloaded the videos off of here https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4 I just saved the same video twice under two different names.
How to replicate the problem: Tap the first cell, then scroll all the way down and then scroll back up, you will notice the video starts appearing all over the place. I just want the video to appear in its proper location and no where else.
Here is a link for the code: Code link
...ANSWER
Answered 2022-Mar-14 at 11:05Here are a few things I would think about / consider changing in trying to implement what you want and which might be the reason we see this strange cell behavior:
Use
indexPath.item
ratherindexPath.row
when dealing with collection viewsIn you
prepareForReuse
, you actually discard theplayerView
so when you try to restore the player again from cacheplayerView?.player = player
- theplayerView
is most likely nil and needs to be reinitializedYou don't need to hang onto the the cell as a whole, this might work, however I think we should let collection view do its business of recycling the cell. Hang onto just the player instead
I have not done it, however, think about how handle removing notification observers when discarding the cells as you might be subscribing to a notification more than once and this could cause issues down the line
I also haven't done this, but remember to remove the video from your cache when you the video finishes since you don't want the cell to react anymore
Here are some small changes I made:
CustomCell
QUESTION
I have an array of arrays
...ANSWER
Answered 2022-Mar-11 at 07:07You should reload collectionView after setting new data.
QUESTION
I ran into a problem when using the simplest UICollectionView and UICollectionViewFlowLayout.
The collection itself works fine, but when the cell is removed, there are problems with the animation.
Here is a code example that demonstrates the problem:
...ANSWER
Answered 2022-Mar-04 at 11:02It seems like there is a problem with your array. It's created dynamically and has conflicts with UICollectionView's implementation.
Try replacing your array with the following static array.
QUESTION
I am trying to show HeaderView in my UICollectionView class and I use UICollectionReusableView class for that.
Actually I am showing HeaderView in my CollectionView but It does not reach to safe area.
I use auto layout programmatically and I wrote extension to do that.
Here is my class and extensions that I use in my code:
...ANSWER
Answered 2022-Feb-09 at 06:31The UICollectionReusableView
is set up fine I believe and I think an automatic inset is applied to the UICollectionView
because of the safe area.
Try one of the two options below in your viewDidLoad
and it might work
QUESTION
users. I'm having an issue that I can't seem to figure out. I want to show a UIMenu when I press a row in my UICollectionView, so I've added a UIButton that spands edge-to-edge in each cell. When the button is pressed, a UIMenu appears. The problem is that the UICollectionView is not scroll-able with a UIButton in each cell. The system prioritises the UIButton over scrolling. I'd love to just have a UILabel and a menu showing when 'didSelectItemAt indexPath' is called, but UIMenus only work with UIButton and UINavigationBarButton.
If someone has a solution for me, please help out! Thank you very much, kind regards 😊
...ANSWER
Answered 2022-Jan-23 at 09:38I suspect and I could be wrong, you have set delaysContentTouches
to false for the UICollectionView.
This would make any touch be interpreted as a button tap.
Instead of removing the button from the cell, here is my set up which sounds similar to yours and gives the desired end result:
Custom UICollectionView with a label and button that spans the whole collection view cell
QUESTION
I have a custom UICollectionViewFlowLayout that centers each cell. To do this, I overrode targetContentOffset
, which the collection view calls whenever the user lifts up their finger. However, once I rotate the device, the cells get off center — targetContentOffset
is not called.
Note 1: After rotating, just swipe a bit on the cells, and they bounce back to center...
Note 2: This gets printed in my console:
ANSWER
Answered 2021-Dec-12 at 11:33As far as I can see, the method is getting called not when you just rotate the device, but when the layout changes. Meaning, if you change from Landscape Left
to Landscape Right
the delegate method is not called — however if you rotating from any Landscape
to Portrait
or other way around, it is working fine.
For maintaining the centered collection view cell, add the targetContentOffset(forProposedContentOffset:)
method. This is called after a rotation, and is not the same as your current targetContentOffset(forProposedContentOffset:withScrollingVelocity:)
method. In your final code, you should use both of these methods. To summarize:
targetContentOffset(forProposedContentOffset:)
is called after a layout changetargetContentOffset(forProposedContentOffset:withScrollingVelocity:)
is called when the user lifts their finger
So, in your PagingFlowLayout
class, paste the following code:
QUESTION
I have a SwiftUI app which supports both LTR and RTL languages. It is not fixated to either one of those, it just depends on what user wants.
I have a horizontally scrollable list of things inside a vertically scrollable list of things, previously achieved by UICollectionView
inside a UITableViewCell
inside a UITableView
.
For RTL, the horizontally scrollable row needs to be on the first element by default which is the rightmost (opposite of LTR obviously). I have found no way yet to make this happen.
I tried flipsForRightToLeftLayoutDirection(_:)
but the problem is it flips everything, including the Text()
inside the scrolling views. So the Arabic text looks mirrored.
Here is my skeleton of the view -
...ANSWER
Answered 2021-Nov-17 at 14:20To automatically scroll to the rightmost element you can use the scrollTo function of the ScrollViewReader view.
You should set an id to each element of the ForEach loop and use the onAppear modifier of the ForEach to scroll to the rightmost element (the last id). This should be done only if language direction is right to left (Locale.characterDirection gives this information).
The code below illustrates this:
QUESTION
So I have a collection view that populates three default images on each cell. The user can select images through the new PHPicker, what I want to accomplish is
- to replace default images with selected photos, so the first selected image should replace the camera cell and so on ... (see images through links at the bottom)
- to display the default images in case user deletes the selected images
currently when I send a new photo to the imgArray it gets displayed in a new cell before the camera cell, as I'm using insert method like so: imgArray.insert(image, at: 0).
My code:
...ANSWER
Answered 2021-Oct-30 at 18:34One way to do this is to keep two image arrays, defaultImages
of type [UIImage]
and inputImages
of type [UIImage?]
. The defaultImages
will hold your camera and photo images, and inputImages
will hold images selected by the user. Initialize the images as:
QUESTION
My horizontal collection view (only when it has 0 cells) causes a crash when attempting to refresh the parent view. When there are 0 items (i.e. "shownStations") for the collection view, the collection view is hidden. When refreshing the parent view, an API call is made to get any available items for the collection view. The code of the collection view that seems relevant to the error message (below) is as follows:
...ANSWER
Answered 2021-Oct-27 at 20:34Somewhere in your program someone is probably calling scrollToItems(at:,scrollPosition:)
. They either don't know the collection is empty and are just passing in (row:0, item:0)
as the index path instead of just skipping the scroll call altogether. Or they think your collection contains at least one item.
To further diagnose the issue, I would either set a breakpoint on exceptions or set a breakpoint on the UIScrollView
function and look at the backtrace to see who is making the call.
You also want to check your Data Source to make sure it's been updated with the correct number of items at the time the scroll happens.
But having a backtrace to find out who or what is causing the scrollview to scroll would be a great first step.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install UICollectionView
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page