2014-02-13 48 views
0

在我的应用程序中,我试图创建一个接口生成器支持景观和肖像在我的垫和iPhone。应用程序支持应用程序在ipad和iphone的景观和potrait模式[iOS]

[在机器人我们使用填充父AUTORESIZE动态创建UI-Elements.is有任何语法在IOS到在自动调整]

1.How到UI元素创建动态地同时支持风景模式和人像模式。

2.如何创建视图控制器来支持横向模式和纵向模式。

3.是否需要动态创建所有视图和UI元素。

请给我解决方案来解决这个问题。我从这么多天的Google努力得到妥善的解决方案。请帮助我。

+0

使用自动尺寸面膜或者你可以去HTTP - 在您的视图控制器创建的方法。com/50319 /开始自动布局教程在ios-7-part-2 – morroko

回答

0

您可以使用自动布局来提供纵向和横向模式。

有关更多详细信息,请检查:What is Auto Layout?

您必须设置横向和纵向模式的约束条件才能正常工作。就像如果你想在顶部有一个按钮一样,你可以在它上面设置约束:从顶部到左边等等。

如果您希望UI元素的工作动态更改,您只需根据需要更改方向上的框架即可。示例代码是在这里:

# pragma mark - Orientation related methods 

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(3_0) 
{ 
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 
     [self deviceRotatedToLandscapeMode]; 
    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
     [self deviceRotatedToLandscapeMode]; 
    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { 
     [self deviceRotatedToPortraitMode]; 
    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     [self deviceRotatedToPortraitMode]; 
    } 

} 

- (void) deviceRotatedToPortraitMode { 

    self.mTableView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height); 

} 

- (void) deviceRotatedToLandscapeMode { 

    self.mTableView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.height, self.view.frame.size.height); 

} 
+0

此自动布局对我来说是正常工作 – Anupama

+0

请参阅我的编辑.... @ Anupama –

2

1)如果你将不是开发厦门国际银行或笔尖只在一个模式纵向或横向厦门国际银行或笔尖。比使用下面的Autoresizing选项更适合任何控件。

Auto layout

http://www.raywenderlich.com/50319/beginning-auto-layout-tutorial-in-ios-7-part-2。您可以使用此链接进行自动布局。

但是,自动布局不能正常工作,因为你想。所以你需要使用自动布局来设置控制帧。

2)如果你想动态开发比使用下面的代码,你可以设置所有控件的框架。 在ViewwillAppear

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil]; 

viewDidLoad中 设置你的控制如下。

UILabel lbl - [UILabel alloc]init]; 


-(void)orientationChanged{ 

     if(Orientation is portrait){ 
      [lbl setFrame:for portrait]; 
    }else{ 
      [lbl setFrame: for landscape]; 
    } 

如果设备更改模式比上述通知触发,并在该方法。你可以设置控制帧。

我希望你能得到你的答案。 //www.raywenderlich:

+0

我必须在orientationChanged方法中实现 – Anupama

+0

您必须更改控件的框架。如果肖像比设置它,如果风景比设置它。得到它了。? –

+0

我的问题是如何动态创建UI元素以支持Land Land和肖像模式 – Anupama

0

最可靠的方法 - 此

-(void)setFrameForOrientationChange:(UIDeviceOrientation*) o { 
//... 
implement your code for frame settings.. 
} 
相关问题