how i can swipe down (scroll) one cell from my tableviewcell (static cells) and make this cell fullscreen?
I know how make the cell full height:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return tableView.frame.size.height;
}
But how i can start this cell with a fixed height and after swipe down (scroll) the cell, make the cell fullscreen?
Thank you
The way I do this sort of thing is actually to treat this as a master-detail interface. The gesture does not really expand the cell; it does a "push" of another view controller containing the full-screen version. And it does it with a custom transition animation, so that it looks like the cell is expanding to form the full-screen version.
And the same thing when returning (popping), in reverse.
This is an example; it isn't 100% identical to what you're doing, but it shows how the push-plus-custom-animation can give the sort of effect you're after:
You can also monitor frame changes in your cell class and expand when the cell is pressed, (not scroll if that's what you really want) and by monitoring frame change you can expand the cells height. Let me know if you want more information because this is on selection, not on scroll.
Related
I have 4 components in my cell.
UIView
UITextView
UIImageView
Another UIView on top of the UIImageView
UIView
UIView
These content can be changed according the data that comes from the server(Sometimes it needs to hide the 3rd image view, sometimes 5th UIView). I'm using auto layout and with the auto layout what is the way to change height of the cell?
You can achieve this easily by using UIStackView. Stack views are a powerful tool for quickly and easily designing your user interfaces. Their attributes allow a high degree of control over how they lay out their arranged views.
Here is link for tutorial - Tutorial
If you hide a view from stackview it conveniently disappears from the layout, but it's still a subview of the stack view. So you don't have to do anything special if you want to bring it back later on. And by using self sizing cells, cells will automatically expand or collapse based on stack view height.
Do following steps:
When you hide any component give that component frame height as 0 and reload tableview. If you giving any component constant height then take outlet of height constraint and make it zero and specify its constant height again when you unhide.
When you unhide give him specific frame height and reload tableView.
heightForRow must returnUITableViewAutomaticDimension
As you already taken components from the storyboard so compiler understands the height of cell and work accordingly.
If you still facing issue you can ask.
this two methods are use for dynamic cell height
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
I post this for other man meet my issue.
Do not apply any change that will change the cell height in layoutSubviews, like hidden view or change any view's height.
Hello I want to create a UITableviewCell like this.
There can be 1 or more attached documents.How can I show attached documents if there are more than 1 documents.
Can I use a A UITableview inside the UITableViewCell? If so how? What is the best way that I can achieve this?
Please help me.
Thanks
A vertical scrolling inside a UITableViewCell would be kind of strange and complicated because you can also scroll in the normal table view. Wouldn´t it be a better solution for you to set the height of the cell depending on the number of attached items. One pseudo example:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return cell.attachedItems.count * 50
}
Then a cell with more attached items would be bigger and you could keep the normal table view scrolling flow.
By default the height of my cell is set to 140.
But if expanded, it should be set to 265.
This is what I have:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
if(expanded){
return 265.0
}else{
return 140.0
}
}
The problem is, I need to scroll down, and scroll back up for the cell to change height. How do I fix this?
Secondary question (more interested in the above question, just if anyone happens to know)
Is it possible to have the cell animate from height 140 to 165?
Thanks
You need to reload the table view after you change anything in it like so:
tableView.reloadData()
When you scroll away from the cell, if it goes off the screen it is unloaded. When you scroll back up, it reloads it. You are basically just reloading the data as scrolling would do.
This code should work here:
tableView.reloadData()
It will reload the table everytime you changes something.
Source
I have a custom UITableView - Scroll, Paging Enable. Because each of my cell has one background image, I want each time I scroll up or down it will display each image as full screen. I try to make my UITableViewCell to be full screen (stretch its height as big as the tableview).
However, I've got a problem: when I scroll(paging), the cell doesn't display as full screen. It contains a small part of the next cell. Then the part of next cell increase bigger and bigger each time I scroll(paging) down.
I didn't see any Auto Layout Option for UITableViewCell, cannot add constraint to the prototype cell. Would you please suggest me the way to do it? Thank you very much.
i just add this two lines of code and it works for me
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return tableView.frame.size.height;
}
// ***** The following SWIFT function expands the cell image view to full screen (frame.size.height), adding to M.Salah's reply above.
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return tableView.frame.size.height;
}
I'm looking just for general scenario.The idea is when app launches user can see only first cell of UITableView at the bottom of UIViewController. When user scrolls up full table appears and when scrolls down only first cell is displayed again. Something similar like keyboard in Facebook messenger app, but with tableView. For now I added tableView as subview to scrollView, but problem is tableView appears from top to bottom, and I'm looking for solution how to make this work upside down.. So, tableView have to appear from bottom to top of UIViewController.
My idea would be:
Give your UITableView the desired frame at viewDiDLoad (probably the height of 1 cell, at the bottom of your UIView)
Let your UIViewController implement UIScrollViewDelegate
At - (void)scrollViewDidScroll:(UIScrollView *)scrollView of UIScrollViewDelegate check which element is scrolling (if its your UITableView) and also check which direction user is scrolling
Change the frame of the UITableView as you wish, you will also have to come up with some logic to block further changing of the UITableView's frame (a BOOL would do good here I guess)
Not sure I understand your correctly but, maybe, this will be helpful
I believe you can try to add zero cell (or first section header view of your UITableView) with transparent background. So that your first cell will be placed on the bottom of screen and UITableView height will be equal to screen height.
In this case, you will have only one scrolling view (UITableView, in particularly). Following method can be used to perform expandable animation and scroll table to top to hide zero cell when user taps on first cell:
[UITableView scrollRectToVisible:animated:]
After that you can leave UITableView as it is and "constrict" your table whenever you need in the same way as it was expanded before.
I understand what you want to do.
In general, UITableView shows cells from top to bottom.
You can add transform in tableview:
tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
Then your tableview will show the cells from bottom to top and you can scroll tableview from bottom to top.
But cells will be transformed as tableview, so you have to add same transform to cells also.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")
**cell.transform = tableView.transform**
return cell
}
All done. Hope to helpful!