重叠UITextView边框

时间:2013-02-27 12:06:07

标签: iphone ios uiview uiinterfaceorientation

我需要为我的应用程序支持横向和纵向方向,并冒险使用单个UIView。

当我第一次模拟应用程序时,它会显示结果而不会出现问题。但是,当我将方向更改为横向时,会出现问题。

我第一次以肖像方式运行应用程序: 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 个答案:

答案 0 :(得分:1)

您只想添加几个视图。

[self.view addSubview:descriptionTextView];

要摆脱这一行,您可以将字段descriptionTextView添加到ViewController子类并更改该文本视图的框架,而无需在self.view中添加/删除它。 此外,您应该尝试使用AutoResizing蒙版来查看是否可以获得所需的结果而无需手动更改帧。 你应该小心这些常数:在3.5英寸和4.0英寸模拟器设备上试用你的应用程序。

相关问题