如何在 UISplitViewController 中获取 detailViewController 的视图大小
How to get detailViewController's view size in UISplitViewController
iOS 8+ ,Objective-C
我正在研究 UISplitViewController
,我正在 detailViewController 上实现 textFields。我有额外两个按钮的底部视图,底部视图的高度为 60px,宽度取决于设备旋转。
所以,我想知道当splitViewController的displayMode为UISplitViewControllerDisplayModeAllVisible
时,如何获取detailViewController的视图大小。
如有任何帮助,我们将不胜感激。
编辑:
我正在尝试使用 viewController、
中的以下代码
#define TABBAR_HEIGHT 50.0f
#define NAVIGATION_HEIGHT 64.0f
#pragma mark- ScreenRotation
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[self calculateFrameForFooterView];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
- (BOOL)shouldAutorotate{
return YES;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (void)calculateFrameForFooterView{
//Caculate frame for footerView
[self addBarButton];
if(self.view.frame.size.width != frameClose.size.width){
frameClose = CGRectMake(0,footerView.frame.origin.y,self.view.frame.size.width,footerView.frame.size.height);
}
frameClose.origin.y = self.view.frame.size.height- footerView.frame.size.height;
CGFloat y;
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
NSLog(@"\n\n**(Landscap)self.view.frame.size(%@)",NSStringFromCGSize(self.view.frame.size));
frameClose.origin.y = self.view.frame.size.height- (footerView.frame.size.height);
y = self.view.frame.size.height-(KEYBOARD_HEIGHT+footerView.frame.size.height+TABBAR_HEIGHT+NAVIGATION_HEIGHT-20);
}else if(orientation == UIDeviceOrientationPortrait){
NSLog(@"\n\n**(Portrait)self.view.frame.size(%@)",NSStringFromCGSize(self.view.frame.size));
frameClose.origin.y = self.view.frame.size.height- (footerView.frame.size.height+TABBAR_HEIGHT+NAVIGATION_HEIGHT);
y = self.view.frame.size.height-(KEYBOARD_HEIGHT+TABBAR_HEIGHT+NAVIGATION_HEIGHT+footerView.frame.size.height);
}
frameOpen = CGRectMake(0,y,footerView.frame.size.width,footerView.frame.size.height);
}
好的,我在 - (void)viewWillLayoutSubviews{}
中解决了我的问题。
当我第二次旋转设备时,这个方法称为 twice.in,我收到了准确的尺寸。
所以首先,我从 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{}
中删除 - (void)calculateFrameForFooterView
而不是将 - (void)calculateFrameForFooterView
放入 - (void)viewWillLayoutSubviews{}
.
所以,最终通过这样做解决了我的问题。然而,这个解决方案并不完美,但这对我有用。这样我就不会接受自己的答案并等待好的答案。
谢谢
iOS 8+ ,Objective-C
我正在研究 UISplitViewController
,我正在 detailViewController 上实现 textFields。我有额外两个按钮的底部视图,底部视图的高度为 60px,宽度取决于设备旋转。
所以,我想知道当splitViewController的displayMode为UISplitViewControllerDisplayModeAllVisible
时,如何获取detailViewController的视图大小。
如有任何帮助,我们将不胜感激。
编辑:
我正在尝试使用 viewController、
#define TABBAR_HEIGHT 50.0f
#define NAVIGATION_HEIGHT 64.0f
#pragma mark- ScreenRotation
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[self calculateFrameForFooterView];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
- (BOOL)shouldAutorotate{
return YES;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (void)calculateFrameForFooterView{
//Caculate frame for footerView
[self addBarButton];
if(self.view.frame.size.width != frameClose.size.width){
frameClose = CGRectMake(0,footerView.frame.origin.y,self.view.frame.size.width,footerView.frame.size.height);
}
frameClose.origin.y = self.view.frame.size.height- footerView.frame.size.height;
CGFloat y;
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){
NSLog(@"\n\n**(Landscap)self.view.frame.size(%@)",NSStringFromCGSize(self.view.frame.size));
frameClose.origin.y = self.view.frame.size.height- (footerView.frame.size.height);
y = self.view.frame.size.height-(KEYBOARD_HEIGHT+footerView.frame.size.height+TABBAR_HEIGHT+NAVIGATION_HEIGHT-20);
}else if(orientation == UIDeviceOrientationPortrait){
NSLog(@"\n\n**(Portrait)self.view.frame.size(%@)",NSStringFromCGSize(self.view.frame.size));
frameClose.origin.y = self.view.frame.size.height- (footerView.frame.size.height+TABBAR_HEIGHT+NAVIGATION_HEIGHT);
y = self.view.frame.size.height-(KEYBOARD_HEIGHT+TABBAR_HEIGHT+NAVIGATION_HEIGHT+footerView.frame.size.height);
}
frameOpen = CGRectMake(0,y,footerView.frame.size.width,footerView.frame.size.height);
}
好的,我在 - (void)viewWillLayoutSubviews{}
中解决了我的问题。
当我第二次旋转设备时,这个方法称为 twice.in,我收到了准确的尺寸。
所以首先,我从 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{}
中删除 - (void)calculateFrameForFooterView
而不是将 - (void)calculateFrameForFooterView
放入 - (void)viewWillLayoutSubviews{}
.
所以,最终通过这样做解决了我的问题。然而,这个解决方案并不完美,但这对我有用。这样我就不会接受自己的答案并等待好的答案。
谢谢