badeen / JLBPartialModal

This class attempts to mimic the interface in National Geographic's Park Guides app for iPhone. It requires iOS 5 for its use of UIViewController Containment. It also uses ARC and literal syntax for arrays. Video: http://f.cl.ly/items/3P1x0I2b1l241U360V1M/JLBPartialModal%20720p.mov
19 stars 3 forks source link

Showing the keyboard #4

Open Rigter opened 11 years ago

Rigter commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

Could you put the code here?

bleft commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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