繁体   English   中英

如何在设备定向期间设置UITextfield位置

[英]How to set UITextfield position during device orientation

我在该图像视图上有一个图像视图,在此放置了两个textField。 当我将设备置于纵向模式时,UITextfield上的位置正确。 一旦我旋转了UITextfiled的设备位置,就更改了。 请帮助我。我正在使用IOS 6,谢谢。

有很多方法可以实现它:1.约束(从xcode-> editor-> pin进行调整)2.务实地。

我个人建议您对此有深刻的了解

雷·温德利希(Ray Wenderlich)

尝试实现-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 旋转设备时将调用此方法。 在这里,您可以设置UITextField的框架。

或者,您可以尝试设置AutoresizingMask。

  1. 您可以通过自动布局(iOS6的新功能)来实现。 您在iOS6中创建的任何新xib将默认启用自动布局。 您必须调整约束。 为此,请选择您的文本字段和图像视图。 现在,从Xcode的Editor菜单中,选择Pin。 固定您的文本字段和图像视图。

有关自动布局的更多信息,请阅读此很棒的教程。 http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2

  1. 您也可以通过务实地实现这一目标。

在willAnimateRotationToInterfaceOrientation中为文本字段和图像设置框架

   - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
                                     duration:(NSTimeInterval)duration
   {
        [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];

        if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
        ||  toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            // set frame for your text field and image in landscape orientation.
        }
        else
        {
            // set frame for your text field and image in landscape orientation.
        }
   }

而已。

暂无
暂无

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

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