UIPicker & iOS 8

145 views Asked by At

I created a UIPickerView in code only when it appears that iOS 8 the view the item is positioned at the top. How do I get it down? This is the code used:

                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)];
                }
3

There are 3 answers

2
emotality On BEST ANSWER
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)

After launching the iPhone 5 (taller screen), when you need something to start from the bottom, you need to do SCREEN_HEIGHT-objectHeight. If you want it to start from top you start with 0.

Now the iPhone 6 and 6+ (wider screen) is here, you must do with the left and right side, left you start with 0 and right you start with SCREEN_WIDTH-objectWidth.

So from now on, no one will be using width as just 320. If you want it the whole screen width, we all need to use SCREEN_WIDTH.

0
Vincenzo On

Fixed with

                    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)];
                        }
                    }
0
Vincenzo On

I modified the code as below and now everything is displayed correctly in the bottom (on the iPhone 4 and 5). But on the iPhone and 6 Plus is shown much lower and I can not shake the picker. How so?

                // 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)];
                }