Простой вопрос iPad - браузер Safari - панель поиска Google - PullRequest
0 голосов
/ 12 декабря 2010

Я пытаюсь создать панель поиска, похожую на панель браузера Safari на iPad. Я думаю, что это только UITextview. При нажатии на элемент управления его размер будет увеличиваться. И когда ориентация поворачивается, она сохраняет размер соответственно. Как я могу добиться этого с помощью опции автоматического изменения размера? Или я должен кодировать вручную, чтобы достичь этого?

Ответы [ 2 ]

1 голос
/ 12 декабря 2010

Вы можете сделать все это непосредственно в Интерфейсном Разработчике.

Компонент панели поиска предоставляет вам соответствующую функциональность.Чтобы правильно изменить размер панели, вам нужно просто прикрепить ее к соответствующим сторонам экрана и сделать ее растягиваемой.Попробуйте открыть этот файл с IB для примера.

0 голосов
/ 02 августа 2012
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];

        }
    }


}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...