Collection view Cell Animations - ios

I am trying to animate UICollectionviewCells as they are created. I wanted to give each collectionviewcell a frame whose origin would be outside the phone and then I try to animate them, the way I wanted to do this was to use animate with duration and save their actual frames so that I can have the collectionviewCells animate to the so called "actual frames", the problem now is that, so I make one collectionViewcell in one section, so every collectionviewcell has "0" as its origin for the "actual frame", I won't be able to get the correct frames on the screen to animate a uicollectionview cell too. Would anyone have any suggestion for me to achieve the animation?

You may want to check this link: http://www.objc.io/issue-12/collectionview-animations.html.
The standardized idea is to subclass UICollectionViewLayout and then implement the method initialLayoutAttributesForAppearingItemAtIndexPath: to provide the initial positioning properties of the cells.
P.S. Other animations (when you remove a cell or when you rotate your device) are also talked about in the post. Read them if you are interested.

Related

Re-orderable custom collectionview layout

I sub-classed UIcollectionViewLayout to create my own layout. In the prepareLayout() method I create the frames for the attributes of each cell because I know where they should be. The frames for each cell are hardcoded. However, I can't hard-code the position of the frames because I want to be able to drag and drop cells. UICollectionViews have nice functions for that:
`collectionView.updateInteractiveMovementTargetPosition(_:position)`.
But this function can't change the location of the cells if their position is hard-coded.
Additionally if the cell is not in it's position it seems to disappear from the view. I want to dynamically change the position of a cell when I begin to drag it. Should I call invalidateLayout() somewhere? I have a UICollectionView as a subview of my UIViewcontroller.
So I've attached a longPress gesture recognizer to my collection view.
I faced this issue few months ago, you cant reload selected cells, the only way is reload whole Collection View. If you have any other solution, pls share me. Thanks

Adding subview to UICollectionView - disables scrolling

I want to add a subview to a UICollectionView in order to make a left panel that scrolls with the collectionview.
Using
[self.collectionView addSubview:myView]
all touches become disabled and I can no longer scroll the view. I've read that adding a subview to a collectionView like this is bad practice.. is this true? Why does it disable touches from reaching the collectionView event when
userInteractionEnabled = NO
I'm trying to do this: imgur link by grabbing the frame position of the first cell in each section, and adding a dot with to myView with the same y value.
Thanks for any help!
Adding subviews using the addSubview: method to a UICollectionView is very bad practice. It can cause a lot of different problems in the normal behaviour of the CollectionView. It can obstruct the views underneath it, capture the touch events, preventing them from reaching the actual scrollView inside the CollectionView, etc. The subviews added using this method will also not scroll as the other elements in the CollectionView do.
The correct way to do what you want is to implement a new type of UICollectionViewCell for the dots, and compute their locations in the prepareForLayout and layoutAttributesForElementsInRect: methods. Basically you'll have either one or two cells in each row. Which ones will have two rows will be determined by you in the methods I've mentioned.
In fact, Apple's docs have a perfect example that's even more complex than what you're trying you achieve. You should check it out from this link.
May I know the purpose of that scroll view ? Because, if you're looking for a subview that displays only a label or image etc., You can use custom collectionview cell instead if I am not wrong... Hope it helps :) :)

Move subview inside UICollectionViewCell upon touch

I have a issue in moving the frames inside UICollectionViewCell.
I have a small dot(made up of UIView) present inside the UICollectionViewCell and I have set the UIPanGestureRecognizer on my UICollectionView. Upon panning if the dot is being touched and moved, I want to move the dot inside the cell. I am able to change the frame of dot correctly(as shown by debugger), but the same is not getting reflected on the device screen. Please can someone suggest me what could possibly be wrong. I expect that somehow I have to refresh the views so that same can be reflected on device screen.
Some points if necessary:
1) I have subclassed UICollectionViewFlowLayout and using my own layout.
2) I have kept the UIPanGestureRecognizer on the entire UICollectionView and not in each UICollectionViewCell. I do not want to keep the UIPanGestureRecognizer in each cell. So please do not suggest me that.
edit: 3) The project is not using autolayout.
Yes, I have tried searching on this, but I am unable to find any suitable solution.

position custom cell in a tableview not fully showing a cell

Okay What i want to do is position a custom cell so that the cell looks like only a portion of it is shown in the UITableView. When you swipe it to the left it goes to a new viewcontroller that allows the user to add details for a new cell. My question is how do we position the UITableViewCell to show only a portion of it in the tableView?
What i want to do is position a custom cell so that the row is not shown fully like about 1/4th or 1/2 its actual length only in the table view
here is an app with the functionality i'm trying to implement this is the image url as i can't post images yet
http://a3.mzstatic.com/us/r30/Purple6/v4/01/16/ec/0116ec99-0206-d125-7d27-d5956b918635/screen568x568.jpeg
I want to implement my cells just like how they implemented their expenses in cells, the cell is positioned according to the amount in it ,if the amount is high the cell is placed further to the left else only 1/4th of the cell is shown(empty cell no expense )
Can we achieve this by making an imageview in a customcell and then changing the x-axis of the image view according to the amount entered in the cell? Thanks in advance
For this, I would do it this way :
For each of my model cell I add a state, in the delegate of UItableView i use heightForRowAtIndex to set the size depends of the cell's state.
To not show extra view (when the cell is cliped) use :
[myCellview setClipToBounds:YES];
I think it should do the tricks. Even if it's not the best way to do it!
Solved it i Just had to add a scroll view to the cell's content view and then add a view containing the color to the scroll view. So its coding is similar to the swipe deletion in 'UITablView'
https://github.com/TeehanLax/UITableViewCell-Swipe-for-Options
this repository helped me out, i only had to make a few changes otherwise that was it thanks for all your suggestions :)

How to replace the plus/minus button of Grouped UITableView in editing mode?

What i am trying to figure out is to add an UIImageView in front of the grouped UITableView while it is in editing mode, just like the ways plus/minus button behaves. There is hell a lot of footprint to build a room there if we could make use of it.
Is there any solution or workaround?
Thanks in advance!
You should be able to just add a UIImageView as a subview to the table cell and give it a negative left offset to put it outside the cell frame.
The cell may clip to its bounds by default (I don't recall offhand), but if it does, just set the table cell's clipToBounds property to NO.
You must override the UIView method layoutSubviews of your table view and check for the editing state. Then you can redraw the cell to your heart's content.

Resources