ios - 旋转设备时调整 tableView 的大小

标签 ios objective-c xcode resize tableview

旋转设备时,我的应用程序出现问题。 tableView 扩展到设备 View ,导致无法访问。

如何让表格调整大小,以免发生这种情况?

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        NSLog(@"Device is rotated sidewise");

        myTable.delegate = self;
        myTable.dataSource = self;
        myTable.scrollEnabled = YES;

        [self.view addSubview:myTable];

        myTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 148, 320, 10)];
    }
}

在使用 xcode 或 objective-c 进行编码时,我完全是个菜鸟。我目前正在研究这个,所以请对你的回答保持友好。

最佳答案

尝试使用自动调整大小蒙版,不要在方向上设置框架。使用下面的链接了解自动调整大小。使用自动调整大小,您无需以编程方式编写任何代码。 http://www.techpaa.com/2012/05/understanding-uiview-autoresizing.html

关于ios - 旋转设备时调整 tableView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21622939/

相关文章:

ios - 字典中的字符串值是字符串的两倍

objective-c - 使用 NSCharacterSet 删除所有不需要的字符

swift - 如何在 swift 4 中访问 View 定义内的其他 View

ios - 来自数据库的 Realm 部分日期?

ios - 找不到实例方法(返回类型默认为 'id' )

ios - 如何在 iOS 中获取所有应用程序的 ViewControllers?

ios - 设置 ViewController 的 managedObjectContext

ios - 如何使用带有自动布局约束的动画移动 View 在 iOS 上

objective-c - 从服务器读取XML文件

ios - 如何将 NSData 写入 Swift 中的新文件?