2013-02-27 346 views
0

我需要支持我的應用程序的橫向和縱向方向,並冒險使用單個UIView。重疊UITextView邊框

當我第一次模擬應用程序時,它顯示的結果沒有問題。但是,當我將方向改爲橫向時,會出現問題。

我第一次在縱向運行應用程序: enter image description here

當我改變方向爲橫向: enter image description here 注意左下角,信息標籤附近。

當我將方向改回肖像時: enter image description here 情況變得更糟。

我使用的代碼,

- (void)updateLayoutForNewOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    CGFloat height = CGRectGetHeight([[UIScreen mainScreen] bounds]); 
    CGFloat width = CGRectGetWidth([[UIScreen mainScreen] bounds]); 

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     NSLog(@"Portrait"); 
     [self iPhoneUserInterfacePortrait:width height:height]; 
    } 

    else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
     NSLog(@"Landscape"); 
     [self iPhoneUserInterfaceLandscape:width height:height]; 
    } 
} 

- (void)iPhoneUserInterfacePortrait:(CGFloat)width height:(CGFloat)height 
{ 
    UITextView *descriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, width - 100.0, height - 300.0)]; 

    [self makeBorder:descriptionTextView]; 
    [self setInformation:descriptionTextView]; 
    [self.view addSubview:descriptionTextView]; 
} 

- (void)iPhoneUserInterfaceLandscape:(CGFloat)width height:(CGFloat)height 
{ 
    UITextView *descriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, width + 230, height - 368.0)]; 

    [self makeBorder:descriptionTextView]; 
    [self setInformation:descriptionTextView]; 
    [self.view addSubview:descriptionTextView]; 
} 

- (void)makeBorder:(UITextView *)descriptionTextView 
{ 
    descriptionTextView.layer.borderWidth = 3.0; 
    descriptionTextView.layer.cornerRadius = 15.0; 
    descriptionTextView.layer.borderColor = [[UIColor grayColor] CGColor]; 

    [self.view addSubview:descriptionTextView]; 
} 

回答

1

,而你只想要一個你要添加一些看法。

[self.view addSubview:descriptionTextView]; 

爲了擺脫這一行的,你可以添加字段descriptionTextView到文本鑑於您的ViewController子類和變化框架無需添加/從self.view刪除。 另外,您應該嘗試使用AutoResizing蒙版進行遊戲,以查看您是否可以在不實際更改幀的情況下獲得所需結果。 你應該小心這個常量:在3.5和4.0英寸模擬器設備上試用你的應用程序。