I have a UITableView which is composed of custom cells. There are 21 cells containing text fields.
When I try to scroll and edit the cells at the bottom of the UITableView, I can't manage to get my cells properly positioned above the keyboard.
Also i created a custom cell class separately for my cells. So keyboard delegates are available on that class only.
I have seen many answers talking about changing view sizes,etc... but none of them has worked nicely so far.
Could anybody clarify the "right" way to do this with a concrete code example?
There are three approaches to this problem all of which tie into the keyboard did / will show notification....
When the keyboard appears, you move the whole view (including tableview) up to ensure the selected textfield is shown on screen, you can calculate this by getting the keyboard height (from the notification) and the textfield position.
You can resize the tableview so that it is only as big as the portion of the screen not covered by the keyboard, again get the height from the notification.
You can set the content inset for the tableview (for the bottom value) to the height of the keyboard.
If you need to, when resizing or repositioning the tableview, you may need to set it to scroll the content to the rect of the text field to ensure it is in view...
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
Related
In my tvOS-app I use a tableView with custom cells. If the cell is higher than the TV-screen it will show the "center-part" of the cell (top and bottom are not visible) and scrolling up or down will center the cell above or below. Is it possible and if, how, to change the "jumping" from cell to cell to a smooth scrolling like in iOS?
You should limit your cells to use a fixed height for a few lines of text and show focus. When a user selects one of the cells you can then expand / zoom / transition to show the whole text is a specific scrollable text view. This interface maintains the users understanding of content, lists and block text.
Just found the solution. Knowing what to search could be an advantage ;-)
Adding this simple line gives me the handling like in iOS:
self.tableView.panGestureRecognizer.allowedTouchTypes = #[#(UITouchTypeIndirect)];
I'm trying to figure out a way to keep a UICollectionViewCell from being removed (didEndDisplayingCell) from my UICollectionView when its original scroll position scrolls off of the view. I know this is the way a UICollectionView is supposed to work, that cells are removed and returned to the reuse pool when they are no longer visible, but this is based on their original position in the UICollectionView. I'm trying to drag that cell past the original visible area into a further away location, but it gets removed killing the pan gesture in progress and killing its view in the collection view once its original position is scrolled out of view. Is there a way to override this behavior and hold onto a UICollectionViewCell until I'm done with it?
I've seen the other ways to attack this problem by creating an image of the cell and dragging that instead, but that won't satisfy my purposes. I need the original cell to survive beyond its original screen position as I scroll through the UICollectionView.
Make copy when dragging your cell around and hide original cell.
I am trying to initiate a scroll view in my UITextView and even though I seem to have selected the appropriate boxes, I can't seem to get the scrolling working. I have gone through multiple questions similar to this but none seem to have the answer.
I included an image of Xcode below:
Question 2: When I scroll down the majority of my text shows but the scrolling stops with two sentences or so left and I have to scroll down and hold it there to read. Any way I can fix this so it scrolls all the way to the bottom of the text?
Can you check the two boxes: Bounce Horizontally and Bounce Vertically and see what's happening? Sometimes your content are actually way bigger than your view, and they are touching a invisible outer box. If you can see they actually move, that means there is nothing wrong with touch or scroll, is just the view layout problem.
For the content issue, my guess is that the content size is not right, you can programmatically adjust it with textView.frame property, set it to a proper size, such as the frame of the window or the frame of the content, which are CGRect classes. Comment below to see if this can solve your second problem.
The text view will not scroll in storyboard, only the app. And the text view will scroll once the content in the text view exceeds the frame size.
If you're using iOS 7+, you can just turn on auto layout, pin each of the sides of the text view to the edge of its parent view, and it works fine without needing to do anything in code.
I'm trying to achieve an effect wherein as a tableview is scrolling, the currently visible cells will animate according to where they are positioned on the screen. I'm somewhat new to IOS dev, so let me try to break it down:
Tableview loads with custom cells User begins scrolling While the
table is in motion, the visible cells have a UIView in which I would
like to perform an animation that corresponds directly to the cell's
current Y position on the screen.
Cells will ONLY animate when they
are visible
Cell animation directly corresponds to table motion, i.e.
whenever the table view scrolls, the cells are animating; once the
table stops, the animations pause
One solution I have thought of is to update drawRect every single frame when the tableview is moving. Depending on the graphic operations, this could be horrible performance wise. Is there a way to grab the current table position every time it changes? Would I be better suited to use Core Animation?
This might be helpful if you want to achieve something like below:
https://github.com/mrugrajsinh/AnimatedTableViewCellDemo
Make your view controllers the delegate of the UITableView, and use all the methods of scrollview Delegate also. There you have many controls for start scrolling and end scrolling, and within thpse controls you could check for uitableview cell positioning.
You have to become delegate to this: https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html
and this is the method to override and animate your cells:
– tableView:willDisplayCell:forRowAtIndexPath:
To allow high-performance editing of UITableView cells I maintain a single UITextField which is displayed/hidden as needed. I've extended UITableView so that double-tapping a cell enters text edit mode, at which stage the text field is added as a subview to the tapped UITableViewCell and becomes the first responder. The cell textLabel is purposefully hidden at this point.
My issue is: I set the same frame and same font for my UITableViewCell and the UITextField, yet the two do not exactly overlap. I have produced an image illustrating this behaviour: the left side shows on top the UITableViewCell textLabel, below this is the UITextField overlaid with cell textLabel hidden, and on the right are both made visible.
I'm not keen on "fudge factor" value fixes, so can anyone tell me what's missing?
I am running the app under iOS 4.2 in the xcode iPad simulator.
Many thanks!
Textfield might just align its content differently. Give the textfid a border to see if it really has the same size as your cell's content view (are you adding to that? Or to the cell's view?)
If the textfield and the cell match, I don't see a problem using a fudge factor.