1

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

4

2 回答 2

0

首先你应该抓住方向:

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

  }

}
于 2013-05-02T06:14:03.070 回答
0

您是否尝试在旋转委托方法中设置 searchBar 的框架或尝试在 XIB 中自动调整大小。

请参阅this以获得更好的主意。

于 2013-05-02T05:00:51.543 回答