Property 'frame' not found on object of type 'UISearchBar' error

空扰寡人 提交于 2019-12-12 04:24:52

问题


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.


回答1:


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)];


来源:https://stackoverflow.com/questions/17846660/property-frame-not-found-on-object-of-type-uisearchbar-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!