简体   繁体   English

在iOS 7中如何在屏幕方向更改时更改视图控制器的位置?

[英]How to change position of the View Controller on screen orientation change in iOS 7?

I want to create iOS application which have Header,Container and Footer just like iOS default Camera app have. 我想创建具有Header,Container和Footer的iOS应用程序,就像iOS默认的Camera应用程序一样。 Header have title and footer have 4 buttons and Container load url in UIWebView. 标头包含标题,页脚具有4个按钮,UIWebView中包含容器加载URL。 Now when i change orientation of the screen i want that header come to top and container below header and footer will come to right side of the screen with horizontal button. 现在,当我更改屏幕的方向时,我希望该标题位于顶部,而标题和页脚下方的容器将通过水平按钮到达屏幕的右侧。 How can i achieve this effect in iOS 7. 如何在iOS 7中达到此效果。

Here is a screen shot how my app look like in Portrait and in Landscape. 这是我的应用程序在“纵向”和“横向”下的外观的屏幕截图。 在此处输入图片说明 在此处输入图片说明

I tried UIStackView but it only support iOS9+ and i also try to use OAStackView but its not working properly. 我尝试了UIStackView,但它仅支持iOS9 +,我也尝试使用OAStackView,但无法正常工作。 Please help me out. 请帮帮我。

My suggestion is you should have two footer views one at the bottom and other at the right side of the view, 我的建议是您应该有两个页脚视图,一个在底部,另一个在视图的右侧,

set the hidden property for the footer view based on the orientation, 根据方向为页脚视图设置hidden属性,

change the size of the container view in the method 在方法中更改容器视图的大小

-(void)viewDidLayoutSubviews{

*if(PORTRAIT){

    self.containerview.frame=CGRectMake(self.view.frame.orign.x, self.headerview.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-footer.view.frame.size.height);

    rightSideFooterView.hidden = YES;
    bottomFooterView.hidden = NO;

else {

self.containerview.frame=CGRectMake(self.view.frame.origin.x, self.headerview.frame.size.height, self.view.frame.size.width-footer.view.frame.size.width, self.view.frame.size.height);
rightSideFooterView.hidden = NO;
bottomFooterView.hidden = YES;
}*

I think this may solve your problem, am not sure this is the best way but this is one of the way to handle this 我认为这可能会解决您的问题,不确定这是最好的方法,但这是处理此问题的方法之一

For the tool bar, I will design two custom tool bars. 对于工具栏,我将设计两个自定义工具栏。 For example, toolBarL for landscape, and toolBarP for portrait. 例如, toolBarL用于横向, toolBarP用于纵向。

When in landscape, let toolBarL show and hidden toolBarP . 在横向时,让toolBarL显示并隐藏toolBarP And in portrait mode, show toolBarP and hidden toolBarL . 在纵向模式下,显示toolBarP和隐藏的toolBarL

Override the method willRotateToInterfaceOrientation:duration: of UIViewController for rotating orientation. 重写UIViewController willRotateToInterfaceOrientation:duration:方法以旋转方向。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        // UI for portrait 
    } else {
        // UI for landscape
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM