UIPicker & iOS 8
Posted
技术标签:
【中文标题】UIPicker & iOS 8【英文标题】: 【发布时间】:2014-11-12 20:17:39 【问题描述】:我在代码中创建了一个 UIPickerView,仅当 ios 8 显示该项目的视图位于顶部时。我怎么把它弄下来?这是使用的代码:
show actionsheet
pickerActionSheet = [self actionSheetSimulationWithPickerView:picker withToolbar:pickerViewToolbar];
// set frames on different orientation
if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
picker.frame = CGRectMake(0, 32, SCREEN_HEIGHT, 162);
pickerViewToolbar.frame = CGRectMake(0, 0, SCREEN_HEIGHT, 32);
[pickerActionSheet setBounds:CGRectMake(0, 0, SCREEN_HEIGHT, 366)];
else
picker.frame = CGRectMake(0, 44, SCREEN_WIDTH, 216);
pickerViewToolbar.frame = CGRectMake(0, 0, SCREEN_WIDTH, 44);
[pickerActionSheet setBounds:CGRectMake(0, 0, SCREEN_WIDTH, 496)];
【问题讨论】:
【参考方案1】:if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
[pickerActionSheet setBounds:CGRectMake(0, SCREEN_WIDTH-194, SCREEN_HEIGHT, 194)];
pickerViewToolbar.frame = CGRectMake(0, 0, SCREEN_HEIGHT, 32);
picker.frame = CGRectMake(0, 32, SCREEN_HEIGHT, 162);
else
[pickerActionSheet setBounds:CGRectMake(0, SCREEN_HEIGHT-216, SCREEN_WIDTH, 260)];
pickerViewToolbar.frame = CGRectMake(0, 0, SCREEN_WIDTH, 44);
picker.frame = CGRectMake(0, 44, SCREEN_WIDTH, 216);
// CGRectMake(start point x, start point y, width, height)
启动iPhone 5(高屏)后,当你需要从底部开始的时候,你需要做SCREEN_HEIGHT-objectHeight
。如果您希望它从顶部开始,请从 0 开始。
现在 iPhone 6 和 6+(更宽的屏幕)来了,你必须左右两边,左边从 0 开始,右边从 SCREEN_WIDTH-objectWidth
开始。
所以从现在开始,没有人会只使用 320 的宽度。如果你想要整个屏幕的宽度,我们都需要使用SCREEN_WIDTH
。
【讨论】:
谢谢它的工作。代替工具栏?它似乎不起作用。 如果pickerActionSheet
是工具栏和工作表的UIView
,我认为以上是正确的。如果不是,只需更改尺寸即可。【参考方案2】:
我修改了如下代码,现在所有内容都正确显示在底部(在 iPhone 4 和 5 上)。但在 iPhone 和 6 Plus 上显示的要低得多,我无法摇动选择器。怎么样?
// set frames on different orientation
if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
picker.frame = CGRectMake(0, SCREEN_WIDTH-162, SCREEN_HEIGHT, 162);
pickerViewToolbar.frame = CGRectMake(0, 0, SCREEN_HEIGHT, 32);
[pickerActionSheet setBounds:CGRectMake(0, 0, SCREEN_HEIGHT, 366)];
else
picker.frame = CGRectMake(0, SCREEN_HEIGHT-216, SCREEN_WIDTH, 216);
pickerViewToolbar.frame = CGRectMake(0, SCREEN_HEIGHT-260, SCREEN_WIDTH, 44);
[pickerActionSheet setBounds:CGRectMake(0, 0, SCREEN_WIDTH, 496)];
【讨论】:
【参考方案3】:固定为
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 667)
[pickerActionSheet setBounds:CGRectMake(0, 0, SCREEN_WIDTH, 667)];
if(result.height == 736)
[pickerActionSheet setBounds:CGRectMake(0, 0, SCREEN_WIDTH, 736)];
if(result.height < 667)
[pickerActionSheet setBounds:CGRectMake(0, 0, SCREEN_WIDTH, 496)];
【讨论】:
以上是关于UIPicker & iOS 8的主要内容,如果未能解决你的问题,请参考以下文章
UIPicker 和 UIActionsheet 不再工作 iOS7