Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Remove iOS 6 deprecation warnings. Dynamically get keyboard height (fix
Browse files Browse the repository at this point in the history
#2).
  • Loading branch information
radutzan committed Oct 10, 2012
1 parent 40f8928 commit 1812d29
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions OLGhostAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ @interface OLGhostAlertView ()
@property NSTimeInterval timeout;
@property UIInterfaceOrientation interfaceOrientation;
@property BOOL isShowingKeyboard;
@property CGFloat keyboardHeight;

@end

Expand Down Expand Up @@ -49,33 +50,49 @@ - (id)initWithFrame:(CGRect)frame
_title = [[UILabel alloc] initWithFrame:CGRectMake(HORIZONTAL_PADDING, VERTICAL_PADDING, 0, 0)];
_title.backgroundColor = [UIColor clearColor];
_title.textColor = [UIColor whiteColor];
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
_title.textAlignment = UITextAlignmentCenter;
#else
_title.textAlignment = NSTextAlignmentCenter;
#endif
_title.font = [UIFont boldSystemFontOfSize:TITLE_FONT_SIZE];
_title.numberOfLines = 0;
_title.lineBreakMode = UILineBreakModeWordWrap;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
_title.textAlignment = UILineBreakModeWordWrap;
#else
_title.lineBreakMode = NSLineBreakByWordWrapping;
#endif

[self addSubview:_title];

_message = [[UILabel alloc] initWithFrame:CGRectMake(HORIZONTAL_PADDING, 0, 0, 0)];
_message.backgroundColor = [UIColor clearColor];
_message.textColor = [UIColor whiteColor];
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
_message.textAlignment = UITextAlignmentCenter;
#else
_message.textAlignment = NSTextAlignmentCenter;
#endif
_message.font = [UIFont systemFontOfSize:MESSAGE_FONT_SIZE];
_message.numberOfLines = 0;
_message.lineBreakMode = UILineBreakModeWordWrap;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
_message.textAlignment = UILineBreakModeWordWrap;
#else
_message.lineBreakMode = NSLineBreakByWordWrapping;
#endif

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIApplicationDidChangeStatusBarOrientationNotification"
object:nil];

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

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

Expand Down Expand Up @@ -225,14 +242,18 @@ - (void)didRotate:(NSNotification *)notification
[self didChangeScreenBounds];
}

- (void)keyboardWillShow
- (void)keyboardWillShow:(NSNotification*)notification
{
NSDictionary *keyboardInfo = [notification userInfo];
CGSize keyboardSize = [[keyboardInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

self.isShowingKeyboard = YES;
self.keyboardHeight = keyboardSize.height;

[self didChangeScreenBounds];
}

- (void)keyboardWillHide
- (void)keyboardWillHide:(NSNotification*)notification
{
self.isShowingKeyboard = NO;

Expand All @@ -247,15 +268,8 @@ - (void)didChangeScreenBounds
CGFloat screenHeight;

if (self.isShowingKeyboard) {
int keyboardHeight;

if (UIDeviceOrientationIsLandscape(self.interfaceOrientation)) {
keyboardHeight = 352;
} else {
keyboardHeight = 264;
}
screenHeight = screenRect.size.height - self.keyboardHeight;

screenHeight = screenRect.size.height - keyboardHeight;
} else {
screenHeight = screenRect.size.height;
}
Expand Down

0 comments on commit 1812d29

Please sign in to comment.