0

What I am trying to do: I want to move the x and y coordinates of my search bar on a touch event. I have placed my code in viewDidLoad to test it out. However I am getting an error.

Error: Property 'frame' not found on object of type 'UISearchBar'.

My code:

NSNumber *newX = @0;
NSNumber *newY = @0;
[UIView animateWithDuration:0.3f animations:^{
    [UISearchBar setFrame:CGRectMake(newX, newY, UISearchBar.frame.size.width,
                                       yourSearchBar.frame.size.height)];
}
                 completion:^(BOOL finished) {}
 ];

Ultimately I would like that animation/move to be executed when the search bar is selected and then move back after deselect.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
sephiith
  • 1,187
  • 3
  • 23
  • 47
  • Replace `UISearchBar` with a variable of type `UISearchBar *`. – rmaddy Jul 24 '13 at 23:40
  • 1
    You are also passing `NSNumber` instances to a function, `CGRectMake()`, that takes `CGFloat`s. That should be `CGFloat newX = 0;` and `CGFloat newY = 0;`. – Zev Eisenberg Jul 25 '13 at 03:40
  • When I make a variable of UISearchBar do I need to assign that variable to the search bar some how? – sephiith Jul 25 '13 at 04:19

1 Answers1

0

UISearchBar is a class. It doesn't have a class method setFrame. It does have an instance method though and that's what you should be using. So, you need an instance of UISearchBar, either that you already have or you need to create one.

If this is being done when the search bar is selected, your code would be in the delegate method searchBarTextDidBeginEditing: and you would use the supplied parameter:

[searchBar setFrame:CGRectMake(newX, newY, searchBar.frame.size.width, yourSearchBar.frame.size.height)];
Wain
  • 118,658
  • 15
  • 128
  • 151