I'd like to move up my view, when the keyboard is shown. The keyboard (height: 216) should push up my view with it's height. Is this possible with a simple code?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- Popover segue to static cell UITableView causes co
do like this. after keyboard visible use this code
This is the most easiest and efficient way to achieve this:
Add the following constants:
Add this to your view controller:
And add these methods to your code:
To move the view
up
, just change itscenter
. First, keep the original one in aCGPoint
property.Then, change as needed when keyboard shows up:
Finally, restore it when keyboard is hidden:
Add animation sugar as you wish
You have more than one way to know when the keyboard appears.
Observing UIKeyboardDidShowNotification notification.
Do the opposite with
UIKeyboardDidHideNotification
.-OR-
Implement UITextFieldDelegate
Detect when editing begin/end to move views around.
Depending on the actual text fields you may need to track in which field is the user editing, add a timer to avoid moving views too much.
just edit these two methods.
simple answer to all d codes. In the if statement change the value according to the iphone i.e., if iphone 4S change it to 265 and in didbeginediting change the 320 to 240 and if iphone 5 change it to 350 and in didbeginediting method keep it as 320, because it is the logic if u understand
Presumably you have some code calling
[myTextField becomeFirstResponder];
. You should move your view just after this call.This is Tendulkar solution, but keeping in mind original frame size and removing keyboard. This solution works for all devices.
Do not forget set UITextField delegate!