UI搜索栏。不能更改框架 [英] UIsearchBar. Can't change frame

查看:33
本文介绍了UI搜索栏。不能更改框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有UISearchBar。我将其设置为表头视图。当文本开始编辑时,我想将搜索栏设置为我的视图控制器的子视图。搜索栏已正确添加到视图控制器的视图中,但其边框不正确。这是我的代码:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
   UITableView *tableView = ((UITableView *)[((SectionViewController *)sharedInstance.currentViewController).view viewWithTag:1111]);
    [tableView reloadData];

    if([searchBar.text isEqualToString:@"Filter..."])
    {
        searchBar.text = @"";
        for(UIView *subView in searchBar.subviews){
            if([subView isKindOfClass:UITextField.class]){
                [(UITextField*)subView setTextColor:[UIColor blackColor]];
            }
        }
    }
    [((SectionViewController *)sharedInstance.currentViewController).view addSubview:searchBar];
    [searchBar setFrame:CGRectMake(0, 20, 320, 38)];

    [((SectionViewController *)sharedInstance.currentViewController).navigationController setNavigationBarHidden:YES animated:YES];
    [searchBar setShowsCancelButton:YES animated:YES];
}

我想设置帧(0,20,320,38),但得到(0,0,320,38)。另外,搜索栏的初始帧是(0,0,320。38)。请告诉我为什么我会有这个?

推荐答案

UISearchBar很奇怪。您不能自由设置它的框架。这是内部实现的原因。

这篇关于UI搜索栏。不能更改框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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