iOS UISearchBar和UISearchDisplayController中状态栏被覆盖的情况解决

当制作如苹果信息里面的搜索时,你可能做不到那种效果,会出现一些问题

这里列举一些代码

self.edgesForExtendedLayout = UIRectEdgeNone;// 这句代码的意思是不让它扩展布局,当你用UISearchBar 和UIsearchDisplayController的结合时可能会遇见覆盖状态栏的状况这时候你就需要在ViewDidLoad里面写上这句代码。

另外需要将UISearchBar加到UISearchDisplayController上如:sedis=[[UISearchDisplayController alloc]initWithSearchBar:_searchbar2 contentsController:self];

@interface AddFriendController (){

UISearchDisplayController *sedis;

UIView *b;

}

@property (nonatomic,strong) UIButton *serchbar;

@property (nonatomic,strong) UITableView * mytable;

@property (nonatomic,strong) NSMutableArray * datasours;

@property (nonatomic,strong) UISearchBar * searchbar2;

@end

@implementation AddFriendController

- (void)viewDidLoad {

[super viewDidLoad];

self.edgesForExtendedLayout = UIRectEdgeNone;

self.view.backgroundColor=[UIColor whiteColor];

ALLTITLENAME(@"添加好友")

//    self.automaticallyAdjustsScrollViewInsets = NO;

//添加ui

[self AddUI];

//添加AddBar

[self AddBar];

}

-(void)AddUI

{

_searchbar2 =[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, screen_width, 44)];

[_searchbar2 setPlaceholder:@"使用手机号/昵称查找好友"];

_searchbar2.delegate=self;

_searchbar2.translucent = NO;// 让系统的searchBar变得不透明

sedis=[[UISearchDisplayController alloc]initWithSearchBar:_searchbar2 contentsController:self];

[self.view addSubview:_searchbar2];

_mytable=[[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.searchbar2.frame), screen_width, screen_height-109)];

_mytable.delegate=self;

_mytable.dataSource=self;

_mytable.keyboardDismissMode  =  UIScrollViewKeyboardDismissModeOnDrag;// 拖动tableView让键盘消失

CLEAR_TABLE_LIN(_mytable)

[self.view addSubview:self.mytable];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容