从横向到纵向改变方向时,横向宽度减小
我使用tableview与search栏显示控制器,它显示良好的portait和横向视图,但从横向旋转search栏大小减less,如何更改原始大小
首先你应该抓住方向:
//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]; } }
你有没有尝试在旋转委托方法中设置searchBar的框架,或尝试在XIB中自动resize。
看到这个更好的主意。
- 不推荐使用UIBarButtonItemStyleBordered; 相反,我该怎么办?
- NSAppTransportSecurity UIWebView问题
- 如何输出CIFilter到相机视图?
- 现在显示的UIlocalNotification没有启动后台任务
- WCSession.sendMessage工作50/50
- 如何在Swift中的iOS上使用FirebaseUI进行Google身份validation?
- animationinputAccessoryView Swift的高度
- 如何从iPhone应用程序获取instagram用户ID /访问tocken
- 如何在Iphone Phonegap中播放embedded式video