Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TKAlertCenter: Center on application frame instead of window bounds.

  • Loading branch information...
commit 4b5d5069b3991eee28518be4a33acbc067379175 1 parent fa79b7d
@devinross authored
View
4 demo/Classes/AlertsViewController.h
@@ -33,4 +33,8 @@
#import <TapkuLibrary/TapkuLibrary.h>
@interface AlertsViewController : UIViewController
+
+@property (nonatomic,strong) UIBarButtonItem *tapMeItem;
+@property (nonatomic,strong) UITextField *hiddenTextField;
+
@end
View
29 demo/Classes/AlertsViewController.m
@@ -48,8 +48,6 @@ - (void) loadView{
[super loadView];
self.view.backgroundColor = [UIColor whiteColor];
-
-
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Tap Me" style:UIBarButtonItemStyleBordered target:self action:@selector(beer)];
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
self.navigationItem.rightBarButtonItem = item;
@@ -57,16 +55,43 @@ - (void) loadView{
self.toolbarItems = @[item];
}
+
+ self.tapMeItem = item;
+ item.enabled = NO;
+
}
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
+
+ [self performSelector:@selector(showKeyboardAlerts) withObject:nil afterDelay:5.0];
+ [[TKAlertCenter defaultCenter] postAlertWithMessage:@"Hi!"];
+ [[TKAlertCenter defaultCenter] postAlertWithMessage:@"This is the alert system"];
+ [[TKAlertCenter defaultCenter] postAlertWithMessage:@"Use images too!" image:[UIImage imageNamed:@"beer"]];
+
+}
+
+- (void) showKeyboardAlerts{
+
+ self.hiddenTextField = [[UITextField alloc] initWithFrame:CGRectZero];
+ [self.view addSubview:self.hiddenTextField];
+
+ [self.hiddenTextField becomeFirstResponder];
+
[[TKAlertCenter defaultCenter] postAlertWithMessage:@"Hi!"];
[[TKAlertCenter defaultCenter] postAlertWithMessage:@"This is the alert system"];
[[TKAlertCenter defaultCenter] postAlertWithMessage:@"Use images too!" image:[UIImage imageNamed:@"beer"]];
+ [self performSelector:@selector(completedKeyboard) withObject:nil afterDelay:5.0];
}
+- (void) completedKeyboard{
+
+ [self.hiddenTextField resignFirstResponder];
+ self.tapMeItem.enabled = YES;
+}
+
+
- (void) beer{
[[TKAlertCenter defaultCenter] postAlertWithMessage:@"Beer!" image:[UIImage imageNamed:@"beer"]];
}
View
11 src/TapkuLibrary/TKAlertCenter.m
@@ -31,7 +31,7 @@
#import "TKAlertCenter.h"
#import "UIView+TKCategory.h"
-
+#import "TKGlobal.h"
#pragma mark - TKAlertView
@interface TKAlertView : UIView {
@@ -143,7 +143,7 @@ - (id) init{
_active = NO;
- _alertFrame = [UIApplication sharedApplication].keyWindow.bounds;
+ _alertFrame = [UIScreen mainScreen].applicationFrame;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil];
@@ -197,13 +197,12 @@ - (void) showAlerts{
_alertView.transform = CGAffineTransformScale(_alertView.transform, 2, 2);
-
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.15];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationStep2)];
_alertView.transform = CGAffineTransformMakeRotation(degrees * M_PI / 180);
- _alertView.frame = CGRectMake((int)_alertView.frame.origin.x, (int)_alertView.frame.origin.y, _alertView.frame.size.width, _alertView.frame.size.height);
+ _alertView.frame = CGRectIntegral(_alertView.frame);
_alertView.alpha = 1;
[UIView commitAnimations];
@@ -294,7 +293,7 @@ - (void) keyboardWillAppear:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
NSValue* aValue = userInfo[UIKeyboardFrameEndUserInfoKey];
CGRect kf = [aValue CGRectValue];
- CGRect wf = [UIApplication sharedApplication].keyWindow.bounds;
+ CGRect wf = [UIScreen mainScreen].applicationFrame;
[UIView beginAnimations:nil context:nil];
_alertFrame = subtractRect(wf,kf);
@@ -304,7 +303,7 @@ - (void) keyboardWillAppear:(NSNotification *)notification {
}
- (void) keyboardWillDisappear:(NSNotification *) notification {
- _alertFrame = [UIApplication sharedApplication].keyWindow.bounds;
+ _alertFrame = [UIScreen mainScreen].applicationFrame;
}
- (void) orientationWillChange:(NSNotification *) notification {
View
7 src/TapkuLibrary/TKCalendarDayView.m
@@ -243,21 +243,14 @@ - (void) _realignPages{
CGRect r = CGRectInset(self.horizontalScrollView.bounds, HORIZONTAL_PAD, 0);
r.origin.x = self.horizontalScrollView.frame.size.width * i + HORIZONTAL_PAD;
-
-
if(r.size.width != w){
sv.frame = r;
[self _realignEventsAtIndex:i];
}else
sv.frame = r;
-
i++;
-
-
sv.layer.shadowPath = [UIBezierPath bezierPathWithRect:sv.bounds].CGPath;
-
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.