iOS 8 move UIView up when keyboard appears | Issue

前端 未结 3 408
逝去的感伤
逝去的感伤 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!

提交回复
热议问题