Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing the keyboard #4

Open
Rigter opened this issue Nov 7, 2012 · 6 comments
Open

Showing the keyboard #4

Rigter opened this issue Nov 7, 2012 · 6 comments

Comments

@Rigter
Copy link

Rigter commented Nov 7, 2012

Hi.

My problem is this, when I try to show the keyboard at the second view, the first time this happens everything looks fine, the problem comes the second time, the keyboard is smaller but still works in its original size.

First Time

First Time

Second Time

Second Time

I do not know if there is any way to force the second view has the becomeFirstResponder.

Hopefully have any suggestions to solve my problem.

First View

View is called using a IBAction

-(IBAction)accion:(id)sender{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    composeViewController *vc = [sb instantiateViewControllerWithIdentifier:@"composeView"];

    JLBPartialModal *partialModal = [JLBPartialModal sharedInstance];
    partialModal.delegate = vc;

    [partialModal presentViewController:vc dismissal:^{

    }];
}

Second view

The class have 3 delegates, one of them didPresentPartialModalView, I'm using this delegate for show the keyboard after the view and animation ends:

#pragma mark - Partial modal delegate

- (void)didPresentPartialModalView:(JLBPartialModal *)partialModal
{
     self.texto.editable = YES;
     [self.texto becomeFirstResponder];
}

Then, when the user touch Close button the UITextView have resignFirstResponder and with the NSNotificationCenter I know that the keyboard is hidden:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillHide:) name:UIKeyboardDidHideNotification object:nil];
}

- (IBAction)close:(id)sender
{
    self.texto.editable = NO;
    [self.texto resignFirstResponder];
}

-(void)KeyboardWillHide:(NSNotification *) notification {
    [[JLBPartialModal sharedInstance] dismissViewController];
}

- (BOOL)shouldDismissPartialModalView:(JLBPartialModal *)partialModal
{
   return YES;
}

Thanks!

@Rigter
Copy link
Author

Rigter commented Nov 13, 2012

Finally!

I've solved my problem adding removedOnCompletion into JLBPartialModal.m

- (CAKeyframeAnimation *)pullBackAnimation
- (CAKeyframeAnimation *)pushForwardAnimation

Like this:

- (CAKeyframeAnimation *)pullBackAnimation
{
    CATransform3D startTransform = [self perspectiveTransform];
    CATransform3D endTransform = CATransform3DConcat([self windowScaledTransform], startTransform);
    CATransform3D middleTransform = CATransform3DConcat([self windowRotationTransform], startTransform);

    CAKeyframeAnimation *anim = [self windowAnimation];
    anim.values = @[[NSValue valueWithCATransform3D:startTransform], [NSValue valueWithCATransform3D:middleTransform], [NSValue valueWithCATransform3D:endTransform]];

    anim.removedOnCompletion = YES; // Line added

    return anim;
}

- (CAKeyframeAnimation *)pushForwardAnimation
{
    CATransform3D endTransform = [self perspectiveTransform];
    CATransform3D startTransform = CATransform3DConcat([self windowScaledTransform], endTransform);
    CATransform3D middleTransform = CATransform3DConcat([self windowRotationTransform], startTransform);

    CAKeyframeAnimation *anim = [self windowAnimation];
    anim.values = @[[NSValue valueWithCATransform3D:startTransform], [NSValue valueWithCATransform3D:middleTransform], [NSValue valueWithCATransform3D:endTransform]];

     anim.removedOnCompletion = YES; // Line added

    return anim;
}

With this I make sure that the animations are removed :D

@bleft
Copy link

bleft commented Dec 7, 2012

hm this doesn't working for me. With this fix the back-view will be shown with his original full size frame on the end of the animation.

@Rigter
Copy link
Author

Rigter commented Dec 11, 2012

Could you put the code here?

@bleft
Copy link

bleft commented Dec 12, 2012

I'm having no special code. Just take the demo project and put an UISearchBar on top of the PartialModalView. First time UISearchBar becomes first responder everything works well. From the second time on the keyboard will shown with the wrong size.
The problem is, that I'm presenting a half screen size view. So the MainView is still visible in the back. In the moment the animation is removed the back view get his original (full) size.

@Rigter
Copy link
Author

Rigter commented Dec 12, 2012

I'm using this for my app, hope this helps:

In the secondView:

Tip: self.texto is a UITextView

- (void)viewDidLoad{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillHide:) name:UIKeyboardDidHideNotification object:nil];
}

-(void)KeyboardWillHide:(NSNotification *) notification {
    [[JLBPartialModal sharedInstance] dismissViewController];
}

#pragma mark - Partial modal delegate

- (void)didPresentPartialModalView:(JLBPartialModal *)partialModal
{
    self.texto.editable = YES;
    [self.texto becomeFirstResponder];
}

- (BOOL)shouldDismissPartialModalView:(JLBPartialModal *)partialModal
{
    return YES;
}

- (void)didDismissPartialModalView:(JLBPartialModal *)partialModal
{

}

I have a close button in my view, when is touched the action is:

- (IBAction)close:(id)sender
{
    self.texto.editable = NO;
    [self.texto resignFirstResponder];
}

In first place this action only hides the keyboard but fires a NSNotification with the name UIKeyboardDidHideNotification, this notification is executed when the keyboard hiding animation is ending, then, this notification calls a custom method called KeyboardWillHide where I dismiss de view.

Try this, maybe you find a solution.

Dont forget to add the little fix that I found

@bleft
Copy link

bleft commented Dec 14, 2012

thank you for your advice. But with your code "anim.removedOnCompletion = YES;" the view in the back will shown with his normal size. (see picture 2)

first time:
iOS Simulator Bildschirmfoto 14 12 2012 12 55 59

with your fix:
iOS Simulator Bildschirmfoto 14 12 2012 12 56 22

second time and ongoing:
iOS Simulator Bildschirmfoto 14 12 2012 12 51 08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants