Domanda

I was wondering how to swipe the ViewController with a visible keyboard?

in iOS 7 I can swipe the ViewController from side to side, but the keyboard stays put.

in short, I would like to get to the following state:

enter image description here

Thanks!

È stato utile?

Soluzione

Update:

I can't recommend the original solution. While it performed well (when it performed at all), it was an unreliable hack, and could easily break the pop gesture recognizer.

My colleague Dave Lyon came up with a great solution using iOS 7 view controller transitions and packaged it up into a pod:

https://github.com/cotap/TAPKeyboardPop

Once installed, just import the main file and you should be good to go.


Original:

I'd love to know if there's a better way of doing this, but I was able to achieve the behavior by adding the keyboard's view as a subview of the view controller's main view:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.textView.inputAccessoryView = [UIView new];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self
               selector:@selector(keyboardWillHide:)
                   name:UIKeyboardWillHideNotification
                 object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)keyboardWillHide:(NSNotification *)note
{
    if (self.textView.isFirstResponder) {
        UIView *keyboardView = self.textView.inputAccessoryView.superview;
        if (keyboardView) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.view addSubview:keyboardView];
            });
        }
    }
}

I've found you can also animate the keyboard with the gesture (via addTarget:action:), but the performance is abysmal and doesn't cleanly animate if the gesture is prematurely canceled.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top