ios - 如何在横向旋转中使用自动布局调整 UIPickerView/UIDatePickerView 的高度?

标签 ios uikit uipickerview autolayout uidatepicker

当我的应用程序处于横向 View 时,我希望将 UIPickerView/UIDatePickerView 的高度调整为 162。有没有一种简单的方法可以在代码的自动布局中执行此操作?

我目前正在尝试以下处理调整大小的方法:

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                      duration:(NSTimeInterval)duration
{
    NSInteger height = 216;
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        height = 162;
    }

    datePicker.bounds =
        CGRectMake(datePicker.frame.origin.x, datePicker.frame.origin.x,
               datePicker.frame.size.width, height);
}

但是当此代码在横向执行时,我得到以下效果,其中选择器不再绑定(bind)到屏幕的左下角(这是出现在它下方的白色边距):

enter image description here

是否有一种方法或自动布局可以使用 UIPickerView 来处理这种大小调整,或者我应该在我的 View Controller 中的一种 View 旋转方法期间只使用边界矩形?

最佳答案

您可以更改 UIPickerView/UIDatePickerView 的高度,但只能更改为以下值:

  • 162
  • 180
  • 216

关于ios - 如何在横向旋转中使用自动布局调整 UIPickerView/UIDatePickerView 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17516716/

相关文章:

ios - Storyboard中具有不同单元格大小和单元格内容的 UITableViewController

ios - 我如何识别不同的pickerView?

iphone - NSPredicate 格式等同于 SQL 查询

ios - 指定 NSLineBreakMode.byTruncatingTail 会导致在 UILabel 中显示 NSAttributedString 时出现问题

ios - 测试 iOS 定期订阅购买

uikit - 在 SwiftUI 中,如何将循环添加视频作为全屏背景图像?

swift - 用于 UIPIckerView 的 UITapGestureRecognizer

iphone - JSON 数组和排序

ios - Swift 可选 - 解包可选值时意外发现 nil

android - Cordova iOS 未更新最近部署的更改