Subclassing custom UICollectionViewLayout to achieve certain deletion and insertion effect - ios

The following is something that i wish to achieve.
We have a horizontal view that displays three items simultaneously.
when we click a button, the three items slide out of the view and are deleted. 3 more items are then created and are moved into the view to replace the previous 3 items.
we can keep on changing the items endlessly, even if there are only 4 items in total .
I was thinking of using collectionView to achieve this by subclassing the uicollectionviewlayout and use the following two functions.
initialLayoutAttributesForAppearingDecorationElementOfKind:atIndexPath:
finalLayoutAttributesForDisappearingDecorationElementOfKind:atIndexPath:
but i am not able to do it.. Anyone has any idea on how i can go around to achieve this?
Thanks in advance!

Instead why don't you just use the horizontal flowLayout and update the data source for the collection view when the button is pressed and reload/insertCells with the moving out animation ?

Related

Dynamically create buttons inside of UIView

I currently trying to implement a dropdown menu. The content of this menu is supposed to be several buttons. The amount of the buttons is determined by the size of the struct array carsArray.
The title of the button shall be each structs value name:
for n in 0...carsArray.count - 1 {
button.setTitle(carsArray[n].name, .normal)
}
This menu shall slide in from above. To do this, I created a UIView - how can I dynamically create as many buttons as there are entries to the carsArray inside of the UIView?
Additionally, am I right to assume that with every entry the UIView's size have to adjusted? If so, how to also do this with every entry? Or do I have to create a table view to do so?
Is there another, easier way to create such a dropdown menu? Maybe with already from Apple given classes?
The way this can be achieved is by using a UITableView. To implement the opening and closing of dropdown, you would need to add or remove the cells or animate the height of UITableView. To close, you would make the height as 1 row height and to expand, you would make it maximum height or total number of rows height.
This is the library that I created a few months ago for one of my apps. It uses a UITableView to create the drop down. Have a look at this.
Let me know if you face any problem using this. Would be happy to fix.

Putting Text into horizontally UIScrollView and appropriate AutoLayout - Swift

So I want to create a Slider on the top of the UI, each item representing a Category (there will be five items). I don't want to switch to another Controller, when sliding to another Category, I just want to load new data into the current controller. So I guess the UIScrollView is the way to go.
See here for what I want to realize:
I have trouble now to show the name of the chosen Category in the middle of the Slider, and by the same time on the left and right its neighbors.
Using a effective AutoLayout is a also necessary.
Is putting Panels into the UIScrollView the right way?
I am new to iOS-Development and would appreciate any help.
Add a scrollview to the top of your controller, in code configure scrollcontentwidth to screenWidth*5 and on each swipe change reload the data of your controller.

Drag & Drop items between tableViews in same viewController and different viewControllers

I need to Drag and Drop items between tableViews inside the same viewController and between tableviews in different viewControllers. I researched for ways to do this and if there's already any good library. I didn't find anything that does all this so I'll try do from scratch, maybe a combination from this! and this project!
Quite a challenge but my main concern is how to recognize a dragged cell from one view to the other. My idea is to create a parentViewController, common to the viewControllers containing the tableviews and then add a gesture recognizer in the parentViewController so when the item is dropped is not needed to translate the position of one view to another and simply try to identify if the item´s position crosses a view in the same reference system. What you guys think? I would like to know your opinions and expertises for the best way to do this. Or if there's a good project that I can start from there...
Thank you
You can achieve this following-
One parentVC which containing two VC,AVC and BVC
You need to create table View custom (using scroll view)
Each cell in custom table view has on LongPressed gesture which tells to prentVC
I am selected after that on movement of finger move cell (Setting .center property of
cell)
After dropping check his position of X or Y and adds in another view
Just released an open source framework that can achieve this: BetweenKit
There is an example application that can demonstrates recognising drag/drops between 2 controllers using BetweenKit here.
Hope this helps.

Horizontal scroll between several UITableView

I need to display students timetable in an application; a TableView contains a complete week, from Monday to Sunday. I'd like the student to be able to go next week by swiping horizontally, finding a new UITableView filled with the new week.
In other words, I'd like to scroll like photos on Facebook, but with complete UITableView filled with pieces of data.
How to do this programatically? Embedding several UITableView in a UIScrollView?
Thanks a lot...
Sincerely,
Hervé
I've done this before using a UIScrollView with paging enabled.
The other alternative which is slightly more complex but makes it easier to manage each individual table separately is to use a UIPageViewController.
It sits behind the view controller views sort of like a TabBarController or a NavigationController.
You manage it a bit like a UITableView in that it has a datasource and it will ask for the "view controller at index".
Examples of this being used are in the Photos app when you are looking at full size images.
I would suggest you to use UIPageView controller with UIView.... and you can use animations on those views whatever you like.

is it possible to use something like "reloadData" between 2 scroll views in iOS to keep the data loaded efficiently?

I have 2 scroll views. When click one of the buttons in the first Scroll view, some images related to this button will be retrieves from a plist and loaded into the second Scroll view.Is it possible to use something like "reloadData" between the 2 scroll views in iOS to keep the data loaded efficiently? Customers may click the buttons in the first Scroll view frequently, so we have to consider its efficiency and low system cost. Some sample code is appreciated. thanks!
you just simply make two arrays that hold the data of both scrollviews and make a method that empty the scrollview and add all the data again into (both)scrollviews and if you want to delete any element or data then you delete from scrollview as well as delete from array that hold the data of that scrollview then you just call that function and your scrollview is reloaded :-)

Resources