Let my UIPickerView have the same behavior as a keyboard

So, I have a UITableView where one of its lines is a UITextView.

When the user writes something in a UITextView (using the keyboard), the user can scroll through the table view and select another cell. Everything is working.

When the user selects another cell, datePicker appears, and the user can select the specified date. I want the user to be able to scroll the View table the same way as when the keyboard is on the screen.

The problem is that when I look at the collector, the table returns to its previous position (some cells are hidden by the collector).

I assume this is happening because I am adding the collector to the main window as a subview ... but I'm honestly not sure ...

Where (and how) should my collector be added so that it "appears", where does the keyboard appear?

Not sure I was clear ...

Many thanks.

+3
source share
4 answers

I actually did it using UIDatePicker, created my own SlideUpDatePicker, which is animated from below, like a keyboard. It took me a week or two for all this to work perfectly, it was absolutely not easy to get it to work in portrait and landscape, as well as with the navigation controller and its animation.

, . .

My SlideUpDatePicker , , , .

dumpWindows(), UIWindow UIView :

dumpView: <UIWindow: 0x411fd50; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x4120af0>>                                                                                                                                                                                                                                                                                                                                                                                 
dumpView: : <UILayoutContainerView: 0x4123310; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x411f800>>                                                                                                                                                                                                                                                                                                                                                                                 
dumpView: : | <UINavigationTransitionView: 0x4123500; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x41232e0>>                                                                                                                                                                                                                                                                                                                                                     
dumpView: : | : <UIViewControllerWrapperView: 0x4519d30; frame = (0 64; 320 416); autoresize = W+H; layer = <CALayer: 0x4519a40>>                                                                                                                                                                                                                                                                                                                                                                      
dumpView: : | : | <UITableView: 0x7808000; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x45182a0>>                                                                                                                                                                                                                                                                                                                                                                
dumpView: : | : | : <DeleteCell: 0x45196e0; baseClass = UITableViewCell; frame = (0 507; 320 45); opaque = NO; autoresize = W; layer = <CALayer: 0x4519a80>>                                                                                                                                                                                                                                                                                                                                           
dumpView: : | : | : <TextCell: 0x4523280; baseClass = UITableViewCell; frame = (0 442; 320 45); autoresize = W; layer = <CALayer: 0x4521ed0>>                                                                                                                                                                                                                                                                                                                                                          
dumpView: : | : | : <DatePickerCell: 0x45224b0; baseClass = UITableViewCell; frame = (0 398; 320 44); autoresize = W; layer = <CALayer: 0x451e170>>                                                                                                                                                                                                                                                                                                                                                    
dumpView: : | : | : <ButtonCell: 0x4521680; baseClass = UITableViewCell; frame = (0 354; 320 44); autoresize = W; layer = <CALayer: 0x4521750>>                                                                                                                                                                                                                                                                                                                                                        
dumpView: : | : | : <ButtonCell: 0x45209f0; baseClass = UITableViewCell; frame = (0 310; 320 44); autoresize = W; layer = <CALayer: 0x4520ac0>>                                                                                                                                                                                                                                                                                                                                                        
dumpView: : | : | : <ButtonCell: 0x4520100; baseClass = UITableViewCell; frame = (0 266; 320 44); autoresize = W; layer = <CALayer: 0x45201d0>>                                                                                                                                                                                                                                                                                                                                                        
dumpView: : | <UINavigationBar: 0x45018b0; frame = (0 20; 320 44); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x4500fe0>>                                                                                                                                                                                                                                                                                                                                                                  
dumpView: : | : <UINavigationItemView: 0x4522a20; frame = (100 8; 160 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4526310>>                                                                                                                                                                                                                                                                                                                                                     
dumpView: : | : <UINavigationItemButtonView: 0x45230a0; frame = (5 7; 87 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4520260>>                                                                                                                                                                                                                                                                                                                                                  
dumpView: <UITextEffectsWindow: 0x4537080; frame = (0 0; 320 480); opaque = NO; layer = <CALayer: 0x45371c0>>                                                                                                                                                                                                                                                                                                                                                                                          
dumpView: : <UIKeyboard: 0x4536ce0; frame = (0 264; 320 216); opaque = NO; layer = <CALayer: 0x4536f60>>                                                                                                                                                                                                                                                                                                                                                                                               
dumpView: : | <UIKeyboardImpl: 0x4175b10; frame = (0 0; 320 216); opaque = NO; layer = <CALayer: 0x4173f90>>                                                                                                                                                                                                                                                                                                                                                                                           
dumpView: : | : <UIKeyboardLayoutStar: 0x4177d90; frame = (0 0; 320 216); layer = <CALayer: 0x4177610>>                                                                                                                                                                                                                                                                                                                                                                                                
dumpView: : | : | <UIKBKeyplaneView: 0x418a6a0; frame = (0 0; 320 216); userInteractionEnabled = NO; layer = <CALayer: 0x418a750>>                                                                                                                                                                                                                                                                                                                                                                     
dumpView: : | : | : <UIKBKeyView: 0x41748e0; frame = (1 119; 40 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x41545c0>>                                                                                                                                                                                                                                                                                                                                                           
dumpView: : | : | : <UIKBKeyView: 0x417e2d0; frame = (279 119; 40 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x417df10>>                                                                                                                                                                                                                                                                                                                                                         
dumpView: : | : | : <UIKBKeyView: 0x418a780; frame = (1 173; 78 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x417f990>>                                                                                                                                                                                                                                                                                                                                                           
dumpView: : | : | : <UIKBKeyView: 0x418adf0; frame = (81 173; 158 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4180120>>                                                                                                                                                                                                                                                                                                                                                         
dumpView: : | : | : <UIKBKeyView: 0x418cdb0; frame = (241 173; 78 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x418cf20>>                    
0

inputView UIResponder ( UITextField). :

UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
//picker.delegate = self;
//picker.dataSource = self;
//[picker setShowsSelectionIndicator:YES];
textField.inputView = picker;
[picker release];

UIPickerView .

. .

+11

...

...

...

CGRect frame3 = self.tableView.frame;
frame3.size.height = frame3.size.height-216;
self.tableView.frame = frame3;

. !;)

0

lechec, inputView UITextField UIPickerView. .

, : http://nomtek.com/tips-for-developers/working-with-pickers/ , . XCode 4.2 iOS 5.

, . , UITextField, , " ". UITextField " ", .

-(void)handleViewTapGesture:(UITapGestureRecognizer *)gesture
{
    [self endEditing:YES];
}

ViewController. View:

-(void) setLoginView:(LoginView *)loginView
{
    _loginView = loginView;

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.loginView action:@selector(handleTapGesture:)];    

    [tapRecognizer setDelegate:self];  // self implements the UIGestureRecognizerDelegate protocol

    [self.loginView addGestureRecognizer:tapRecognizer];    
}

. , . Apple / .

I should mention that you will need additional code to make sure other controls get branched, you need a delegate that implements the UIGestureRecognizerDelegate protocol and this method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{    
    if ([touch.view isKindOfClass:[UIButton class]])    // Customize appropriately.
        return NO; // Don't let the custom gestureRecognizer handle the touch   

    return YES;
}
0
source

Source: https://habr.com/ru/post/1747405/


All Articles