Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 简单的iPad问题-Safari浏览器-谷歌搜索栏_Iphone_Uitextfield - Fatal编程技术网

Iphone 简单的iPad问题-Safari浏览器-谷歌搜索栏

Iphone 简单的iPad问题-Safari浏览器-谷歌搜索栏,iphone,uitextfield,Iphone,Uitextfield,我正在尝试创建一个类似于iPad上safari浏览器中的搜索栏。我认为这只是一个UITextview。 单击控件时,其大小将展开。当方向旋转时,它会相应地保持大小。 如何使用自动调整大小选项来实现这一点?或者我必须手动编写代码才能实现它吗?您可以直接在Interface Builder中完成所有这些操作 搜索栏组件为您提供了适当的功能。要使该条正确调整大小,只需将其锚定到屏幕的适当侧面并使其可拉伸。试着用IB打开一个例子 Use the below code to your controller

我正在尝试创建一个类似于iPad上safari浏览器中的搜索栏。我认为这只是一个UITextview。 单击控件时,其大小将展开。当方向旋转时,它会相应地保持大小。
如何使用自动调整大小选项来实现这一点?或者我必须手动编写代码才能实现它吗?

您可以直接在Interface Builder中完成所有这些操作

搜索栏组件为您提供了适当的功能。要使该条正确调整大小,只需将其锚定到屏幕的适当侧面并使其可拉伸。试着用IB打开一个例子

Use the below code to your controller and make sure the you have a textfield delegate.

- (void)textFieldDidBeginEditing:(UITextField *)textField
{   
    UIInterfaceOrientation orientation = self.interfaceOrientation;
    if (orientation== UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {

        if(textField==searchField){


            CGRect searchFrame = searchField.frame;
            searchFrame.size.width += 150;
            searchFrame.origin.x -= 150;


            [UIView beginAnimations: @"GrowTextField" context: nil];
            {
                searchField.frame = searchFrame;
                [UIView setAnimationDuration: 0.5];
            }
            [UIView commitAnimations];
      }


    }

    else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {    
         if(textField==searchField){


            CGRect searchFrame = searchField.frame;
            searchFrame.size.width += 150;
            searchFrame.origin.x -= 150;

             [UIView beginAnimations: @"GrowTextField" context: nil];
            {
                searchField.frame = searchFrame;
                [UIView setAnimationDuration: 0.5];
            }
            [UIView commitAnimations];
        }
    }

}



- (void)textFieldDidEndEditing:(UITextField *)textField{
    UIInterfaceOrientation orientation = self.interfaceOrientation;
    if (orientation== UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        if(textField==searchField){

            CGRect searchFrame = searchField.frame;
            searchFrame.size.width -= 150;
            searchFrame.origin.x += 150;


            [UIView beginAnimations: @"ShrinkTextField" context: nil];
            {
                searchField.frame = searchFrame;
                [UIView setAnimationDuration: 0.5];
            }
            [UIView commitAnimations];

       }


    }

    else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {    

        if(textField==searchField){

            CGRect searchFrame = searchField.frame;
            searchFrame.size.width -= 150;
            searchFrame.origin.x += 150;


            [UIView beginAnimations: @"ShrinkTextField" context: nil];
            {
                searchField.frame = searchFrame;
                [UIView setAnimationDuration: 0.5];
            }
            [UIView commitAnimations];

        }
    }


}