简体   繁体   English

如果屏幕超出原始屏幕或屏幕下方,如何将y轴设置为0-在iPad中

[英]How to set the y-axis to 0, if the screen is beyond the orginal screen or below the screen--In iPad

I am in the learning process ,I have this particular code, for whenever we click on the textfield or textview the screen moves up and when we resign the keyboard the screen gets to its original position its working fine for Both Landscape and Portrait Mode 我正在学习过程中,我有这个特殊的代码,因为每当我们单击文本字段或textview时,屏幕就会向上移动;当我们退出键盘时,屏幕会回到其原始位置,无论是横向模式还是纵向模式都可以正常工作

What is the problem is. 问题是什么。 Initially it is in Portrait mode, When We click on the textfield or textview the screen is raising and the keyboard is shown, now when i rotate to landscape and resign the keyboard the screen is getting downwards and the same is happening for the vice-versa. 最初是在“纵向”模式下,当我们单击文本字段或textview时,屏幕将升高并显示键盘,现在当我旋转到横向并退出键盘时,屏幕将向下移动,反之亦然。

    - (void)animateTextField:(UITextField*)textField textView:(UITextView *)textView up:(BOOL)up{   
            int animatedDistance;  
            int moveUpValue; 

            if (textField) {  
                moveUpValue = textField.frame.origin.y+ textField.frame.size.height;  
              }  
           else {  
                moveUpValue = textView.frame.origin.y+ textView.frame.size.height;   
             }  

            NSLog(@"moveup%d",moveUpValue);

            UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

            if (orientation == UIInterfaceOrientationPortrait ||
                 orientation == UIInterfaceOrientationPortraitUpsideDown)
              {
               if(textField){
                  animatedDistance = 216-(650-moveUpValue-5);
                }
               else{
                 animatedDistance = 216-(850-moveUpValue-5);
                }
              }
           else
             {
               if(textField){
                  animatedDistance = 162-(505-moveUpValue-5);
                }
               else{
                  animatedDistance = 162-(750-moveUpValue-5);
             }
         }
         NSLog(@"animated%d",animatedDistance);

        if(animatedDistance>0)
         {
           const int movementDistance = animatedDistance;
           const float movementDuration = 0.3f; 
           int movement = (up ? -movementDistance : movementDistance);
           NSLog(@"movement portrait%d",movement);
           [UIView beginAnimations: nil context: nil];
           [UIView setAnimationBeginsFromCurrentState: YES];
           [UIView setAnimationDuration: movementDuration];
           scrollview.frame = CGRectOffset(scrollview.frame, 0, movement);       
           [UIView commitAnimations];

         }
   }

I would like to now how can i solve this issue, or how can we change the y axis to 0. 我想现在如何解决此问题,或者如何将y轴更改为0。

Please Kindly do help. 请帮忙。 Thanks in Advance 提前致谢

当设备方向改变时,请验证animationDistance设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM