Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS 8中,搜索栏已经越界了。不过,它在iOS 7中运行良好_Ios_Objective C_Iphone_Ipad_Ios8 - Fatal编程技术网

在iOS 8中,搜索栏已经越界了。不过,它在iOS 7中运行良好

在iOS 8中,搜索栏已经越界了。不过,它在iOS 7中运行良好,ios,objective-c,iphone,ipad,ios8,Ios,Objective C,Iphone,Ipad,Ios8,我有自定义搜索栏。每当我在iOS 8中启动时,它都无法正常运行。我也张贴代码 CGRect searchBarFrame = CGRectMake(-10.0, 0.0, self.navigationController.navigationBar.frame.size.width+20, self.navigationController.navigationBar.frame.size.height); if(kEnableScanFunctionality) { //

我有自定义搜索栏。每当我在iOS 8中启动时,它都无法正常运行。我也张贴代码

CGRect searchBarFrame = CGRectMake(-10.0, 0.0, 
  self.navigationController.navigationBar.frame.size.width+20,
  self.navigationController.navigationBar.frame.size.height);

if(kEnableScanFunctionality)
{
    //searchBarFrame.origin.x += 60; //60 is Left BarButtonItem width
    searchBarFrame.size.width = searchBarFrame.size.width - 60.0f;
}

searchBar = [[UISearchBar alloc] initWithFrame:searchBarFrame];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
searchBar.backgroundImage = [self setSeachBarBackgroudImage];
searchBar.placeholder = NSLocalizedString(@"SearchBar_Placeholder",@"Search");

//This code is used to remove 1 pixel height imageView
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0f)
{
    [[searchBar.subviews objectAtIndex:0] removeFromSuperview];
}
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
searchBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[searchBarView setBackgroundColor:[UIColor clearColor]];
searchBar.delegate = self;

//custom cancel button
NSDictionary *attributes = nil;
UIBarButtonItem *cancelBtn = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];

UIImage *cancelImage = nil;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
    cancelImage = [UIImage imageNamed:@"cancelButton.png"];
    attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,[UIFont fontWithName:@"HelveticaNeue" size:14.0f], UITextAttributeFont,nil];
}
else
{
    cancelImage = [[UIImage imageNamed:@"cancelButton.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
    attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,[UIFont fontWithName:@"HelveticaNeue" size:14.0f], NSFontAttributeName,nil];
}

[cancelBtn setBackgroundImage:cancelImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[cancelBtn setTitleTextAttributes:attributes forState:UIControlStateNormal];
[cancelBtn setTitleTextAttributes:attributes forState:UIControlStateHighlighted];

//[cancelBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor],  UITextAttributeTextColor,nil] forState:UIControlStateHighlighted];

[searchBarView addSubview:searchBar];
self.navigationItem.titleView = searchBarView;



if(kEnableScanFunctionality)
{
    //searchBarFrame.origin.x += 60; //60 is Left BarButtonItem width
    searchBarFrame.size.width = searchBarFrame.size.width - 60.0f;
}

searchBar = [[UISearchBar alloc] initWithFrame:searchBarFrame];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;

searchBar.backgroundImage = [self setSeachBarBackgroudImage];

searchBar.placeholder = NSLocalizedString(@"SearchBar_Placeholder",@"Search");

//This code is used to remove 1 pixel height imageView
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0f)
{
    [[searchBar.subviews objectAtIndex:0] removeFromSuperview];
}
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
searchBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[searchBarView setBackgroundColor:[UIColor clearColor]];
searchBar.delegate = self;

//custom cancel button
NSDictionary *attributes = nil;
UIBarButtonItem *cancelBtn = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];

UIImage *cancelImage = nil;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
    cancelImage = [UIImage imageNamed:@"cancelButton.png"];
    attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,[UIFont fontWithName:@"HelveticaNeue" size:14.0f], UITextAttributeFont,nil];
}
else
{
    cancelImage = [[UIImage imageNamed:@"cancelButton.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
    attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,[UIFont fontWithName:@"HelveticaNeue" size:14.0f], NSFontAttributeName,nil];
}

[cancelBtn setBackgroundImage:cancelImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[cancelBtn setTitleTextAttributes:attributes forState:UIControlStateNormal];
[cancelBtn setTitleTextAttributes:attributes forState:UIControlStateHighlighted];

//[cancelBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor],  UITextAttributeTextColor,nil] forState:UIControlStateHighlighted];

[searchBarView addSubview:searchBar];
self.navigationItem.titleView = searchBarView;
CGRect searchBarFrame=CGRectMake(-10.0,0.0,
self.navigationController.navigationBar.frame.size.width+20,
self.navigationController.navigationBar.frame.size.height);
if(可启用扫描功能)
{
//searchBarFrame.origin.x+=60;//60为左BarButtonItem宽度
searchBarFrame.size.width=searchBarFrame.size.width-60.0f;
}
searchBar=[[UISearchBar alloc]initWithFrame:searchBarFrame];
searchBar.autoresizingMask=uiviewsautoresizingflexiblewidth;
searchBar.backgroundImage=[self-seteAchBarBackgroundImage];
searchBar.placeholder=NSLocalizedString(@“searchBar_placeholder”,@“Search”);
//此代码用于删除1像素高度的imageView
如果([[UIDevice currentDevice].systemVersion floatValue]<7.0f)
{
[[searchBar.subviews objectAtIndex:0]从SuperView移除];
}
UIView*searchBarView=[[UIView alloc]initWithFrame:CGRectMake(0.0,0.0,self.navigationController.navigationBar.frame.size.width,self.navigationController.navigationBar.frame.size.height)];
searchBarView.autoresizingMask=UIViewAutoresizingFlexibleWidth;
[searchBarView setBackgroundColor:[UIColor clearColor]];
searchBar.delegate=self;
//自定义取消按钮
NSDictionary*属性=nil;
UIBarButtonItem*cancelBtn=[UIBarButtonItem Appearancewhen contained in:[UISearchBar类],nil];
UIImage*cancelImage=nil;
如果([[[UIDevice currentDevice]系统版本]浮点值]<7.0)
{
cancelImage=[UIImage ImageName:@“cancelButton.png”];
attributes=[NSDictionary Dictionary WithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[UIFont fontWithName:@“HelveticaNeue”大小:14.0f],UITextAttributeFont,无];
}
其他的
{
cancelImage=[[UIImage ImageName:@“cancelButton.png”]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
attributes=[NSDictionary Dictionary WithObjectsandKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont fontWithName:@“Helveticanue”大小:14.0f],NSFontAttributeName,无];
}
[cancelBtn setBackgroundImage:cancelImage for状态:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[cancelBtn setTitleTextAttributes:状态的属性:UIControlStateNormal];
[cancelBtn setTitleTextAttributes:状态的属性:uicontrol状态高亮显示];
//[cancelBtn setTitleTextAttributes:[NSDictionary Dictionary Dictionary WithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]用于状态:UIControlStateHighlighted];
[搜索栏视图添加子视图:搜索栏];
self.navigationItem.titleView=searchBarView;
if(可启用扫描功能)
{
//searchBarFrame.origin.x+=60;//60为左BarButtonItem宽度
searchBarFrame.size.width=searchBarFrame.size.width-60.0f;
}
searchBar=[[UISearchBar alloc]initWithFrame:searchBarFrame];
searchBar.autoresizingMask=uiviewsautoresizingflexiblewidth;
searchBar.backgroundImage=[self-seteAchBarBackgroundImage];
searchBar.placeholder=NSLocalizedString(@“searchBar_placeholder”,@“Search”);
//此代码用于删除1像素高度的imageView
如果([[UIDevice currentDevice].systemVersion floatValue]<7.0f)
{
[[searchBar.subviews objectAtIndex:0]从SuperView移除];
}
UIView*searchBarView=[[UIView alloc]initWithFrame:CGRectMake(0.0,0.0,self.navigationController.navigationBar.frame.size.width,self.navigationController.navigationBar.frame.size.height)];
searchBarView.autoresizingMask=UIViewAutoresizingFlexibleWidth;
[searchBarView setBackgroundColor:[UIColor clearColor]];
searchBar.delegate=self;
//自定义取消按钮
NSDictionary*属性=nil;
UIBarButtonItem*cancelBtn=[UIBarButtonItem Appearancewhen contained in:[UISearchBar类],nil];
UIImage*cancelImage=nil;
如果([[[UIDevice currentDevice]系统版本]浮点值]<7.0)
{
cancelImage=[UIImage ImageName:@“cancelButton.png”];
attributes=[NSDictionary Dictionary WithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[UIFont fontWithName:@“HelveticaNeue”大小:14.0f],UITextAttributeFont,无];
}
其他的
{
cancelImage=[[UIImage ImageName:@“cancelButton.png”]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
attributes=[NSDictionary Dictionary WithObjectsandKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont fontWithName:@“Helveticanue”大小:14.0f],NSFontAttributeName,无];
}
[cancelBtn setBackgroundImage:cancelImage for状态:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[cancelBtn setTitleTextAttributes:状态的属性:UIControlStateNormal];
[cancelBtn setTitleTextAttributes:状态的属性:uicontrol状态高亮显示];
//[cancelBtn setTitleTextAttributes:[NSDictionary Dictionary Dictionary WithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]用于状态:UIControlStateHighlighted];
[搜索栏视图添加子视图:搜索栏];
self.navigationItem.titleView=searchBarView;
如何克服这个问题