Frage

I am trying to implement UIPickerView and I have almost done it. But when I click on text field, picker view appears behind the text field. Here are the snapshots before and after showing picker view.

Before clicking on text field.

enter image description here

After clicking on the text field.

enter image description here

Here you can see that picker view is behind the text field. I want it to be on top.

EDIT Here is the code I am using to show picker view:

-(void) showPickerView 
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.50];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [self.view bringSubviewToFront:self.picker];

    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
    if(iOSDeviceScreenSize.height == 480)
    {
        CGRect frame = self.picker.frame;
        frame.origin.y = 151.0;
        self.picker.frame = frame;
        frame = self.toolBar.frame;
        frame.origin.y = 107.0;
        self.toolBar.frame = frame;
    }
    else if(iOSDeviceScreenSize.height == 568)
    {
        CGRect frame = self.picker.frame;
        frame.origin.y = 239.0;
        self.picker.frame = frame;
        frame = self.toolBar.frame;
        frame.origin.y = 195.0;
        self.toolBar.frame = frame;
    }
    [UIView commitAnimations];
}
War es hilfreich?

Lösung 3

I solved the issue. In fact it was a plum mistake. I placed the pickerView before other views. So when it appears on screen, it appears behind the textfield. I had to put it at the bottom place in my .nib file.

In iOS, the view added before will go behind other views. I missed this concept.

Andere Tipps

In your view hierarchy the textfield may be above pickerview. If you are using xib/storyboard then select pickerview and from menu select Editor>Arrange>Sent to Front.

If you are using code for creating all ui elements add pickerview after adding textfield. or

try

[self.view bringSubViewToFront:pickerView];

use

[self.view bringSubViewToFront:pickerView]

you did't get than please share your code for more explanation we will help..

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top