I am displaying datepicker from bottom. And added as subview of scrollview. When Picker is on screen I can scroll my scrollview thorugh pickerview also. I dont want to scroll that scrollview at that time and I also dont want to disable scroll at the tiome of displaying date picker. I just dont want to interact scrollview thorugh pickerview. I am using ios7
Don't add pickerview in scrollview.When you show pickerview set scrollview height deducting pickerview height and add pickerview in your view as subview instead of scrollview subview.
scrollview.frame = CGRectMake(scrollview.frame.origin.x,scrollview.frame.origin.y,scrollview.frame.size.width,scrollview.frame.size.height-pickerview.frame.size.height)
Related
I have TextView inside a TableView FooterView and that TableView is inside CollectionViewCell.
How to have the TextView move when pressed. Now Keyboard collapses with the textView. It does not scrolls the TableView up by default.
You can use IQKeyboardManager. It will handle all keyboard events.
Take the reference of the bottom constraint of your tableView and then change the constraint constant to keyboard height, then the bottom of your tableView as well as the textView will come just above the keyboard.
I have a tableview with a textview for entering text immediately below it similar to Apple Messages. When the user begins to enter text and the keyboard appears, I want the following behavior similar to IOS Messages.
If the keyboard will not cover anything, the visible part of the tableview remains unchanged.
If the keyboard will cover something, the tableview moves up just enough so that its bottom-most filled cell is just above the keyboard.
Because I'm using autolayout, I currently have a constraint between the tableview and the textview below it. Also, the project has IQKeyboard which manages a lot of other views involving textfields and textviews.
The constraint combined with IQKeyboard accomplishes 2. When the keyboard appears, the keyboard pushes the textview up. The textview pushes the tableview up. So if the tableview is fully populated, you see the last cell of the tableview above the textview above the keyboard as desired.
However, 2. is not working.
if the tableview is not filled, the keyboard pushes up the textview which pushes up the tableview so that you longer see the top of the tableview.
I have tried adjusting the contentOffset property of the tableview when the Keyboard Shows and this sort of works but the tableview initially moves up before coming back down. I think this is because the notification to change the offset property does not fire until after the keyboard has begun to move up.
I also tried adjusting the tableview height to its content but this causes the textview to expand to fill the difference due to constraints.
Content offset approach - problem is that content offset adjusts too late
//register for keyboard notifications and in handler:
if let infoKey = notification.userInfo?[UIKeyboardFrameEndUserInfoKey],
let rawFrame = (infoKey as AnyObject).cgRectValue {
let keyboardFrame = view.convert(rawFrame, from: nil)
self.heightKeyboard = keyboardFrame.size.height
UIView.animate(withDuration: 0.2, animations: {
self.tableView.contentInset = UIEdgeInsetsMake(self.heightKeyboard!, 0, 0, 0);
})
}
Can anyone suggest a way to mimic the behavior of Apple Messages? Thanks in advance for any suggestions.
One approach:
constrain the top of the tableView to the top of the view
constrain the bottom of the tableView to the top of the textField
constrain the bottom of the textField to the bottom of the view
create an #IBOutlet for the textField's bottom constraint
When the keyboard is shown, change the .constant of the textField's bottom constraint to the height of the keyboard view.
This will move the textField up, and because it's top is constrained to the bottom of the tableView, it will also move the tableView's bottom edge up.
Then scroll to the bottom of the tableView.
Layout:
Initial hierarchy, with 20 rows (scrolled to the bottom):
Hierarchy view (tableView background color set to green, so we can see its frame):
View after the keyboard is shown:
Hierarchy after the keyboard is shown:
Little tough to see from static screen caps, but the frame of the green rectangle (the tableView background) is now shorter... the user can still scroll up and down to see all the rows, but the bottom of the tableView is still constrained to the top of the textField.
When you the keyboard is dismissed, set the .constant of the textField's bottom constraint back to Zero.
You can see a full, working example project up on GitHub: https://github.com/DonMag/KBAdjust
In my project,
In the view 'Top' side is for one UIView and below it a tableView. I want to show tableView to top when scrolled and hide the tableView.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.topView.isHidden = true }
Please give me solution for how to show tableView to top when tableView scrolled.
Below is the screenshot
[![enter image description here][1]][1]
in this view bottom is tableView and top is UIView.
Below is the storyboard screenshot.
The simplest solution is to set that topView as tableHeaderView.
self.tableView.tableHeaderView = topView
Now when you scroll the tableView topView will goes up with it. Also no need to implement scrollViewDidScroll now.
Select your tableview in your Controller of Storyboard
Select your TableView
Go to Attributes Inspector on the right panel of Utilities
Set Style to Grouped
I have view controller which has a tableview and below the table view there is a textfield(which is not part of tableview cell) and a button(just like whatsapp chat window)
What I see is, when I start adding objects to the table, it grows up to the text field and grows beyond and below the text field at the bottom.
There are a few different ways to go about it,
In the IB, Make sure that your tableview comes before your textfield and button, The top most view is the farthest one.
You can use UIView methods such as
sendSubviewToBack: (Send tableview to back)
bringSubviewToFront: (Bring textfield and button to front)
Have you tried setting frames to each of these elements?
CGFloat tableViewHeight = 400;
self.tableView setFrame:CGRectMake(0, 0, CGRectGetWidth(self.view), tableViewHeight);
I'd place the textField and button as subviews to a view - self.textFieldElementsView and set the view's frame under the tableView:
self.textFieldElementsView.frame = CGRectMake(0, CGRectGetMinX(self.tableView.frame) + tableViewHeight, CGRectGetWidth(self.view), CGRectGetHeight(self.view)-tableViewHeight);
I would like to increase the keyboard height use in your code by 30. I have a toolbar over my keyboard. I play around with the code but I couldn't make it work. the toolbar over keyboard hides the last cell. I changed this line of code:
if ( offset != -1 ) {
[self setContentOffset:CGPointMake(self.contentOffset.x, offset+30) animated:YES]; // this one
}
I works but the rest of the cell don't get center anymore when clicking on it.
Where in your code is the height of the keyboard?
For that, first you have take scroll view. And add table view inside the scroll view.
After that, you have set scroll view height accordingly.
Like Below:
[scrlPage setFrame:CGRectMake(scrlPage.frame.origin.x, scrlPage.frame.origin.y, scrlPage.frame.size.width, 361.0-150.0)];
[scrlPage setContentSize:CGSizeMake(scrlPage.frame.size.width, 361.0)];
[scrlPage setContentOffset:CGPointMake(0.0, 50.0)];
Hope you will get it.
Though let me know in case of any difficulty.