Logic For Moving Text Field Above Keyboard On Tap

前端 未结 3 1635
猫巷女王i
猫巷女王i 2020-12-05 09:10

Right now, I have basic code for moving the textfield above the keyboard when you start editing. However, the size of the textfield varies based on device and orientation. S

3条回答
  •  佛祖请我去吃肉
    2020-12-05 09:42

    UIViewControllers have a property called interfaceOrientation and the function UIInterfaceOrientationIsPortrait/Landscape so essentially you can do:

    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation){
    //portrait logic
    }
    else{
    //landcapeLogic
    }
    

    inside for each the iPhone and iPad in your view controller. From there you can do your pixel measurement way as you had done before, because as far as I know that's the simplest way to do it.

    P.S. There is a function to check for landscape checker too, but if the first if statement is false meaning the device is not in portrait, then it must be in landscape hence the plain else.

提交回复
热议问题