uicollectionviewcell

Subview frame is incorrect when creating UICollectionViewCell

为君一笑 提交于 2019-12-02 21:47:00
The problem I created a UICollectionViewController with a custom UICollectionViewCell. The custom cell contains a large and rectangular UIView (named colorView) and a UILabel (named nameLabel). When the collection is first populated with its cells and I print colorView.frame, the printed frames have incorrect values. I know they are incorrect, because the colorView frames are larger than the cell frame themselves, even though the colorView gets drawn correctly. However, if I scroll the collectionView enough to trigger a reuse of a previously created cell, the colorView.frame now has correct

Swift: UICollectionView selecting cell indexPath issues

放肆的年华 提交于 2019-12-02 21:02:55
I am trying to do a Collection View whereby someone selects a cell and for each selection it takes them to another View Controller that holds content of the selection. However I'm running into difficulties as once I apply this line of code to didSelectItemAtIndexPath ; self.performSegueWithIdentifer("showDetail", sender: self) and then run it in the Simulator the cell selection is working according the indexPath but its remembering the selections each time I select new cell . So for example each cell has a photo and label and if I select the first cell in the indexPath the segue takes me first

UICollectionView Cell Scroll to centre

这一生的挚爱 提交于 2019-12-02 21:00:49
I am using UICollectionView in my UIViewController. My collectionview properties are set as below. Now I would like cell to be Centre on screen after scroll! Option 1: Option 2: What would I have to do achieve option 2? UPDATE: In the end I have used following code as scrolling with other answer is not smooth. - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity { CGFloat offsetAdjustment = MAXFLOAT; CGFloat horizontalCenter = proposedContentOffset.x + (CGRectGetWidth(self.collectionView.bounds) / 2.0); CGRect targetRect

Animate UICollectionView cell size change and reposition surrounding cells

 ̄綄美尐妖づ 提交于 2019-12-02 20:47:05
Goal: To animate the change of a cell's height and reposition surrounding cells. Scenario: Some cells in a collection view load remote images. Initially, those cells are sized statically and an activity indicator is shown. After an image is loaded, it is added to its cell and the cell's height is changed to fit the photo. Notes: I am animating the cell's frame change with animateWithDuration . This works fine, except an increased cell size has it overlapping the cells below. I've blindly tried calling collectionView.collectionViewLayout invalidateLayout after resizing the target cell and

How to delete an item from UICollectionView with indexpath.row

ε祈祈猫儿з 提交于 2019-12-02 20:41:07
I have a collection view,and I tried to delete a cell from collection view on didSelect method.I succeeded in that using the following method [colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; But now I need to delete the item on button click from CollectionView Cell.Here I get only the indexpath.row. From this I am not able to delete the Item. I tried like this. -(void)remove:(int)i { NSLog(@"index path%d",i); [array removeObjectAtIndex:i]; NSIndexPath *indexPath =[NSIndexPath indexPathForRow:i inSection:0]; [colleVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject

UICollection View Adjust Cell Size for Screen Size

旧街凉风 提交于 2019-12-02 20:11:29
Currently i have a collection view which takes up most of my screen at the 3.5 inch screen size.The collection view is 51 pixels from the top and 20 pixels from the bottom of the screen. I am using the cells with UIPageControl to create a paged layout, with one cell per page. When switching to the 4 inch size, using constraints i can get the collection view to expand into the new space (maintaining the 51 pixels from the top and 20 from bottom), but the cell size stays the same, so now there is a bunch of empty space at the top and bottom of the cell. I tried using constraints, but it appears

Display just two columns, with multiple rows in a CollectionView using storyboard

和自甴很熟 提交于 2019-12-02 19:05:20
I want to display only two cells in a row, no matter what the iPhone screen size is. Like, My storyboard contains a UICollectionView ,connected by constraints. The storyboard settings for the UICollectionView is, Now, when I run this in 6, 5s or below, only one cell appears in a row. The code I'd used is, - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return [categoryImages count]; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ homePageCells *cell =

UICollectionViewCell - contents do not animate alongside cell's contentView

╄→гoц情女王★ 提交于 2019-12-02 18:45:20
Problem looks like this: http://i.imgur.com/5iaAiGQ.mp4 (red is a color of cell.contentView) Here is the code: https://github.com/nezhyborets/UICollectionViewContentsAnimationProblem Current status: The content of UICollectionViewCell's contentView does not animate alongside contentView frame change. It gets the size immediately without animation. Other issues faced when doing the task: The contentView was not animating alongside cell's frame change either, until i did this in UICollectionViewCell subclass: override func awakeFromNib() { super.awakeFromNib() //Because contentView won't animate

Could not cast value of type 'UICollectionViewCell'

眉间皱痕 提交于 2019-12-02 18:41:49
I use a custom CollectionViewCell in my Storyboard. When I start the app I get this message: Could not cast value of type 'UICollectionViewCell' to TestProject.CollectionViewCell. The template for a CollectionViewController in Xcode comes with this line of code in viewDidLoad, which changes the specification in your storyboard. // Register cell classes self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) Simply delete that line. In older Swift versions the line is: // Register cell classes self.collectionView!.registerClass(UICollectionViewCell

Make UICollectionViewCell's height match its content (sum height of all sub views) with AutoLayout

杀马特。学长 韩版系。学妹 提交于 2019-12-02 18:11:41
问题 I found the next answer to make UIView's height match its content https://stackoverflow.com/a/39527226/7767664 I tested it, it works fine (if UIView height size in storyboard bigger or smaller than its content then during runtime it autoresize itself to match the content). But if I use UICollectionViewCell instead of UIView then nothing changes, height of cell is never changed, it always has the hardcoded height we have in storyboard properties: What else can I do? Also I have 2 sections in