2014-02-13 108 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.. 
} 
相關問題