当我的应用程序处于横向 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)到屏幕的左下角(这是出现在它下方的白色边距):
是否有一种方法或自动布局可以使用 UIPickerView 来处理这种大小调整,或者我应该在我的 View Controller 中的一种 View 旋转方法期间只使用边界矩形?
最佳答案
您可以更改 UIPickerView/UIDatePickerView 的高度,但只能更改为以下值:
- 162
- 180
- 216
关于ios - 如何在横向旋转中使用自动布局调整 UIPickerView/UIDatePickerView 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17516716/