2013-02-27 217 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英寸模拟器设备上试用你的应用程序。