在"UISearchBar"类型的对象上找不到属性“框架" [英] Property 'frame' not found on object of type 'UISearchBar' error

查看:59
本文介绍了在"UISearchBar"类型的对象上找不到属性“框架"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做什么:我想在触摸事件中移动搜索栏的x和y坐标.我已将我的代码放在viewDidLoad中进行测试.但是我遇到了错误.

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.

错误:在"UISearchBar"类型的对象上找不到属性框架".

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

我的代码:

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.

推荐答案

UISearchBar 是一个类.它没有类方法 setFrame .它确实有一个实例方法,这就是您应该使用的方法.因此,您需要一个 UISearchBar 实例,该实例已经存在或需要创建一个.

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.

如果在选择搜索栏时执行此操作,则代码将在委托方法 searchBarTextDidBeginEditing:中,并且将使用提供的参数:

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

这篇关于在"UISearchBar"类型的对象上找不到属性“框架"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆