iOS 8 move UIView up when keyboard appears | Issue

前端 未结 3 407
逝去的感伤
逝去的感伤 2021-01-22 12:23

I have a UIView with a UITextField placed at the bottom of the screen which will move up when a keyboard appears.

I have been following the bel

相关标签:
3条回答
  • 2021-01-22 13:01

    I'm not sure if this is your problem but you should use the block based APIs to animate a UIView

    Example (not tested)

    - (void)animateTextField:(UITextField*)textField
                          up:(BOOL)up
    {
        const float movementDuration = 0.5f;
        const int movementDistance = 380;
        int movement = (up ? -movementDistance : movementDistance);
        [UIView animateWithDuration:movementDuration
                         animations:
                         ^{
                            CGRect frame = self.bottomView.frame;
                            frame.origin.y = self.view.frame.size.height - 266.0f;
                            self.bottomView.frame = frame;
    
                         }
        ];
    }
    

    You can read in Apple's doc:

    Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead.

    https://developer.apple.com/Library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html

    Hope it helps you!

    0 讨论(0)
  • 2021-01-22 13:07

    I used this code. It didn't move up in a scroll view. but changed their XY positions. but this is effective in my iPhone 6. i didn't check them with other iPhones.

     func textViewDidBeginEditing(textView: UITextView){
        textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y - 216 , textView.frame.size.width, textView.frame.size.height)
        buttonProp.frame = CGRectMake(buttonProp.frame.origin.x, buttonProp.frame.origin.y - 216, buttonProp.frame.size.width, buttonProp.frame.size.height)
         MessageView.frame = CGRectMake(MessageView.frame.origin.x, MessageView.frame.origin.y - 216, MessageView.frame.size.width, MessageView.frame.size.height)
         datePicked.frame = CGRectMake(datePicked.frame.origin.x, datePicked.frame.origin.y - 216, datePicked.frame.size.width, datePicked.frame.size.height)
    
    }
    
    func textViewDidEndEditing(textView: UITextView){
        textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y + 216, textView.frame.size.width, textView.frame.size.height)
         buttonProp.frame = CGRectMake(buttonProp.frame.origin.x, buttonProp.frame.origin.y + 216, buttonProp.frame.size.width, buttonProp.frame.size.height)
        MessageView.frame = CGRectMake(MessageView.frame.origin.x, MessageView.frame.origin.y + 216, MessageView.frame.size.width, MessageView.frame.size.height)
        datePicked.frame = CGRectMake(datePicked.frame.origin.x, datePicked.frame.origin.y + 216, datePicked.frame.size.width, datePicked.frame.size.height)
    }
    

    All my components are programmed to move when editing begins. and move back after editing. manual editing. yes.

    0 讨论(0)
  • 2021-01-22 13:17

    Get TPKeyboardAvoidingScrollView from https://github.com/michaeltyson/TPKeyboardAvoiding

    use it as follows.

    drop the TPKeyboardAvoidingScrollView.m and TPKeyboardAvoidingScrollView.h source files into your project, pop a UIScrollView into your view controller's xib, set the scroll view's class to TPKeyboardAvoidingScrollView, and put all your controls within that scroll view. You can also create it programmatically, without using a xib - just use the TPKeyboardAvoidingScrollView as your top-level view.

    To disable the automatic "Next" button functionality, change the UITextField's return key type to anything but UIReturnKeyDefault.

    0 讨论(0)
提交回复
热议问题