iphone - 重叠的 UITextView 边框

标签 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];
}

最佳答案

您正在添加多个 View ,而您只需要一个 View 。

[self.view addSubview:descriptionTextView];

要摆脱这一行,您可以将字段 descriptionTextView 添加到 ViewController 子类中,并更改该 TextView 的框架,而无需从 self.view 添加/删除它。 此外,您还应该尝试使用“自动调整大小”蒙版,看看是否可以在不实际手动更改框架的情况下获得所需的结果。 您应该小心这些常量:在 3.5 英寸和 4.0 英寸模拟器设备上尝试您的应用程序。

关于iphone - 重叠的 UITextView 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15111722/

相关文章:

ios - 检测应用程序何时在后台状态 iOS 中被用户杀死

ios - 如何在进入后台后杀死 NSTimer 并在应用程序恢复事件后创建一个新计时器?

由于 iPad icon.png,iPhone 应用程序验证失败

iphone - iOS 6 中的 UIScrollView

ios - 无论设备方向如何,物体都会落向地球

ios - 使用 Xcode 6 仍然得到 "Unable to boot iOS Simulator"

ios - 在 Swift 中,从 JSON 加载的 tableView 数据仅在 80% 的时间内加载

swift - 从其他文件 Swift 在 tabBarController 中呈现 ViewController

iphone - 来自 UIView 的 PresentModalViewController

iOS:如何重用从 Nib 构建的 UIView?