我的应用程序需要支持横向和纵向方向,因此我尝试使用单个 UIView。
当我第一次模拟应用程序时,它显示结果没有问题。但是,当我将方向更改为横向时,就会出现问题。
我第一次纵向运行应用程序:
当我将方向更改为横向时: 请注意左下角,靠近“信息”选项卡。
当我将方向改回纵向时: 情况变得更糟。
我正在使用的代码,
- (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/