当从横向更改为纵向时,uisearch条宽度会减小 [英] uisearch bar width is reduced when change orientation from landscape to portrait

查看:113
本文介绍了当从横向更改为纵向时,uisearch条宽度会减小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有搜索栏显示控制器的tableview,它在portait和横向视图中显示效果很好,但是从横向旋转到纵向搜索栏尺寸减小了,如何更改原始尺寸

I am using tableview with search bar display controller, it shows good in portait and landscape view, but rotate from landscape to portrait search bar size is reduced, how to change the original size

推荐答案

第一个你应该抓住方向:

The first your should catch the orientation:

 //AppDelegate.h
 @interface AppDelegate : UIResponder <UIApplicationDelegate>
 @property (nonatomic, unsafe_unretained) NSInteger isPortrait;

//AppDelegate.m
@synthesize isPortrait;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

   isPortrait = 1;

}

实施状态:

-(void)viewWillAppear:(BOOL)animated{

   [[UIApplication sharedApplication] statusBarOrientation];
   [[UIDevice currentDevice] orientation];
   [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

 //methode deviceRotated 

-(void)deviceRotated:(NSNotification*)notification{

   AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
   UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
   if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
   {
      [self searchBarLandscape];
       app.isPortrait = NO;
  }
  else{
     [self searchBarPortrait];
     app.isPortrait = YES;
  }

}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;
   if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || toInterfaceOrientation == UIInterfaceOrientationPortrait) 
   {
    app.isPortrait = 1;
   }
  else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
  {
    app.isPortrait = 0;
  }
  [self prepareSearchBarOrientation];

}


-(void)prepareSearchBarOrientation
{

   AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;
   if (app.isPortrait)
   {
       [self searchBarPortrait];//Set Frame here
   }
  else
  {
      [self searchBarLandscape];

  }

}

这篇关于当从横向更改为纵向时,uisearch条宽度会减小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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