Permalink
Browse files

Merge branch 'master' of github.com:gpambrozio/BlockAlertsAnd-ActionS…

…heets

Conflicts:
	BlockAlertsDemo.xcodeproj/project.pbxproj
	BlockAlertsDemo/ProjectSpecific/BlockUI.h
	BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m
	BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h
	BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m
	BlockAlertsDemo/ToAddToYourProjects/BlockBackground.h
	BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m
	BlockAlertsDemo/ToAddToYourProjects/BlockTextPromptAlertView.h
	BlockAlertsDemo/ToAddToYourProjects/BlockTextPromptAlertView.m
  • Loading branch information...
2 parents 3e9dda2 + e3276bf commit 676144bdf439fce52cd0d4d6ec60f0d50ac4f25a @barrettj barrettj committed Mar 29, 2013
@@ -24,7 +24,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (IBAction)showAlert:(id)sender
{
BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Alert Title" message:@"This is a very long message, designed just to show you how smart this class is"];
-
+
[alert setCancelButtonWithTitle:@"Cancel" block:nil];
[alert setDestructiveButtonWithTitle:@"Kill!" block:nil];
[alert addButtonWithTitle:@"Show Action Sheet on top" block:^{
@@ -71,21 +71,24 @@ - (IBAction)showActionSheetPlusAlert:(id)sender
- (IBAction)goNuts:(id)sender
{
for (int i=0; i<6; i++)
- {
+ {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.5 * i * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if (arc4random() % 2 == 0)
[self showAlert:nil];
else
[self showActionSheet:nil];
});
- }
+ }
}
- (IBAction)showTextPrompt:(id)sender
{
UITextField *textField;
- BlockTextPromptAlertView *alert = [BlockTextPromptAlertView promptWithTitle:@"Prompt Title" message:@"With prompts you do have to keep in mind limited screen space due to the keyboard" textField:&textField];
+ BlockTextPromptAlertView *alert = [BlockTextPromptAlertView promptWithTitle:@"Prompt Title" message:@"With prompts you do have to keep in mind limited screen space due to the keyboard" textField:&textField block:^(BlockTextPromptAlertView *alert){
+ [alert.textField resignFirstResponder];
+ return YES;
+ }];
[alert setCancelButtonWithTitle:@"Cancel" block:nil];
@@ -16,6 +16,7 @@
}
@property (nonatomic, readonly) UIView *view;
+@property (nonatomic, readwrite) BOOL vignetteBackground;
+ (id)sheetWithTitle:(NSString *)title;
@@ -10,12 +10,12 @@
@implementation BlockActionSheet
@synthesize view = _view;
+@synthesize vignetteBackground = _vignetteBackground;
static UIImage *background = nil;
static UIFont *titleFont = nil;
static UIFont *buttonFont = nil;
-
#pragma mark - init
+ (void)initialize
@@ -72,6 +72,7 @@ - (id)initWithTitle:(NSString *)title
_height += size.height + 5;
}
+ _vignetteBackground = NO;
}
return self;
@@ -190,6 +191,7 @@ - (void)showInView:(UIView *)view
[_view insertSubview:modalBackground atIndex:0];
[modalBackground release];
+ [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground;
[[BlockBackground sharedInstance] addToMainWindow:_view];
CGRect frame = _view.frame;
frame.origin.y = [BlockBackground sharedInstance].bounds.size.height;
@@ -35,7 +35,7 @@
- (void)setupDisplay;
@property (nonatomic, retain) UIImage *backgroundImage;
-
@property (nonatomic, readonly) UIView *view;
+@property (nonatomic, readwrite) BOOL vignetteBackground;
@end
@@ -11,6 +11,7 @@ @implementation BlockAlertView
@synthesize view = _view;
@synthesize backgroundImage = _backgroundImage;
+@synthesize vignetteBackground = _vignetteBackground;
static UIImage *background = nil;
static UIImage *backgroundlandscape = nil;
@@ -160,6 +161,8 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message
if ([self class] == [BlockAlertView class])
[self setupDisplay];
+
+ _vignetteBackground = NO;
}
return self;
@@ -348,6 +351,7 @@ - (void)show
_backgroundImage = nil;
}
+ [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground;
[[BlockBackground sharedInstance] addToMainWindow:_view];
__block CGPoint center = _view.center;
@@ -372,7 +376,9 @@ - (void)show
center.y -= kAlertViewBounce;
_view.center = center;
}
- completion:nil];
+ completion:^(BOOL finished) {
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"AlertViewFinishedAnimations" object:nil];
+ }];
}];
[self retain];
@@ -20,5 +20,6 @@
- (void)removeView:(UIView *)view;
@property (nonatomic, retain) UIImage *backgroundImage;
+@property (nonatomic, readwrite) BOOL vignetteBackground;
@end
@@ -11,6 +11,7 @@
@implementation BlockBackground
@synthesize backgroundImage = _backgroundImage;
+@synthesize vignetteBackground = _vignetteBackground;
static BlockBackground *_sharedInstance = nil;
@@ -65,81 +66,21 @@ - (id)autorelease
return self;
}
-- (void)setRotation:(NSNotification*)notification
-{
- UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
-
- CGRect orientationFrame = [UIScreen mainScreen].bounds;
-
- if(
- (UIInterfaceOrientationIsLandscape(orientation) && orientationFrame.size.height > orientationFrame.size.width) ||
- (UIInterfaceOrientationIsPortrait(orientation) && orientationFrame.size.width > orientationFrame.size.height)
- ) {
- float temp = orientationFrame.size.width;
- orientationFrame.size.width = orientationFrame.size.height;
- orientationFrame.size.height = temp;
- }
-
- self.transform = CGAffineTransformIdentity;
- self.frame = orientationFrame;
-
- CGFloat posY = orientationFrame.size.height/2;
- CGFloat posX = orientationFrame.size.width/2;
-
- CGPoint newCenter;
- CGFloat rotateAngle;
-
- switch (orientation) {
- case UIInterfaceOrientationPortraitUpsideDown:
- rotateAngle = M_PI;
- newCenter = CGPointMake(posX, orientationFrame.size.height-posY);
- break;
- case UIInterfaceOrientationLandscapeLeft:
- rotateAngle = -M_PI/2.0f;
- newCenter = CGPointMake(posY, posX);
- break;
- case UIInterfaceOrientationLandscapeRight:
- rotateAngle = M_PI/2.0f;
- newCenter = CGPointMake(orientationFrame.size.height-posY, posX);
- break;
- default: // UIInterfaceOrientationPortrait
- rotateAngle = 0.0;
- newCenter = CGPointMake(posX, posY);
- break;
- }
-
- self.transform = CGAffineTransformMakeRotation(rotateAngle);
- self.center = newCenter;
-
- [self setNeedsLayout];
- [self layoutSubviews];
-}
-
-
- (id)init
{
self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
if (self) {
self.windowLevel = UIWindowLevelStatusBar;
self.hidden = YES;
- self.userInteractionEnabled = YES;
+ self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(setRotation:)
- name:UIApplicationDidChangeStatusBarOrientationNotification
- object:nil];
- [self setRotation:nil];
+ self.vignetteBackground = NO;
}
return self;
}
- (void)addToMainWindow:(UIView *)view
{
- [self setRotation:nil];
-
- if ([self.subviews containsObject:view]) return;
-
if (self.hidden)
{
_previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain];
@@ -201,4 +142,22 @@ - (void)removeView:(UIView *)view
}
}
+- (void)drawRect:(CGRect)rect
+{
+ if (_backgroundImage || !_vignetteBackground) return;
+ CGContextRef context = UIGraphicsGetCurrentContext();
+
+ size_t locationsCount = 2;
+ CGFloat locations[2] = {0.0f, 1.0f};
+ CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f};
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
+ CGColorSpaceRelease(colorSpace);
+
+ CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
+ float radius = MIN(self.bounds.size.width , self.bounds.size.height) ;
+ CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation);
+ CGGradientRelease(gradient);
+}
+
@end
@@ -11,6 +11,7 @@
@class BlockTextPromptAlertView;
typedef BOOL (^BlockTextPromptAlertShouldDismiss)(NSInteger buttonIndex, BlockTextPromptAlertView* theAlert);
+typedef BOOL(^TextFieldReturnCallBack)(BlockTextPromptAlertView *);
@interface BlockTextPromptAlertView : BlockAlertView <UITextFieldDelegate> {
@@ -24,11 +25,17 @@ typedef BOOL (^BlockTextPromptAlertShouldDismiss)(NSInteger buttonIndex, BlockTe
@property (nonatomic, assign) BOOL disableAutoBecomeFirstResponder;
@property (nonatomic, assign) BOOL selectAllOnBeginEdit;
++ (BlockTextPromptAlertView *)promptWithTitle:(NSString *)title message:(NSString *)message defaultText:(NSString*)defaultText;
++ (BlockTextPromptAlertView *)promptWithTitle:(NSString *)title message:(NSString *)message defaultText:(NSString*)defaultText block:(TextFieldReturnCallBack) block;
+
+ (BlockTextPromptAlertView *)promptWithTitle:(NSString *)title message:(NSString *)message textField:(out UITextField**)textField;
++ (BlockTextPromptAlertView *)promptWithTitle:(NSString *)title message:(NSString *)message textField:(out UITextField**)textField block:(TextFieldReturnCallBack) block;
- (id)initWithTitle:(NSString *)title message:(NSString *)message defaultText:(NSString*)defaultText;
+- (id)initWithTitle:(NSString *)title message:(NSString *)message defaultText:(NSString*)defaultText block: (TextFieldReturnCallBack) block;
+
@property (readwrite, copy) BlockTextPromptAlertShouldDismiss shouldDismiss;
- (void)setAllowableCharacters:(NSString*)accepted;
Oops, something went wrong.

0 comments on commit 676144b

Please sign in to comment.