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

AlertView is not moving up when keyboard comes up #12

Open
AlexanderZubkov opened this issue Feb 15, 2014 · 5 comments
Open

AlertView is not moving up when keyboard comes up #12

AlexanderZubkov opened this issue Feb 15, 2014 · 5 comments

Comments

@AlexanderZubkov
Copy link

Hello.
I've added a textview as a content view and when the keyboard comes up it hides half of alert view, i.e. alert view is not moving up.
Is it possible to make it to move up?
Thanks.

@neywen
Copy link

neywen commented Feb 19, 2014

I had the same issue today, and I chose a way around : I moved the private property alertWindow from CXAlertView.m to the public interface CXAlertView.h , and then :
CXAlertView* alert = [[CXAlertView alloc] blah bla ]
[...]
[alert show];
alert.alertWindow.frame = CGRectMake([...]);

cheers,
l.

@skx926
Copy link
Contributor

skx926 commented May 27, 2014

That's is a big problem,I got this one too

@imironenko
Copy link

I modified CXAlertViewController for solving this issue. Here is some code:

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    [self.alertView setup];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }

  • (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    }

// Handle keyboard show/hide changes

  • (void)keyboardWillShow: (NSNotification *)notification
    {
    CGSize screenSize = self.view.frame.size;
    CGSize dialogSize = self.alertView.frame.size;
    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
    CGFloat tmp = keyboardSize.height;
    keyboardSize.height = keyboardSize.width;
    keyboardSize.width = tmp;
    }

    [UIView animateWithDuration:0.3f delay:0.0 options:UIViewAnimationOptionTransitionNone
    animations:^{
    self.alertView.frame = CGRectMake((screenSize.width - dialogSize.width) / 2, (screenSize.height - keyboardSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height);
    }
    completion:nil
    ];
    }

  • (void)keyboardWillHide: (NSNotification *)notification
    {
    CGSize screenSize = self.view.frame.size;
    CGSize dialogSize = self.alertView.frame.size;

    [UIView animateWithDuration:0.3f delay:0.0 options:UIViewAnimationOptionTransitionNone
    animations:^{
    self.alertView.frame = CGRectMake((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2, dialogSize.width, dialogSize.height);
    }
    completion:nil
    ];
    }

@jlubeck
Copy link

jlubeck commented Aug 19, 2014

Thank you @miriusus !! Make a push request with your code!!!

@aelam
Copy link

aelam commented Mar 31, 2016

+1

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

6 participants