Closed Dimajp closed 8 years ago
Below you can find code of you class with my minor changes (changes to .h can be done by oneself). Hope you'll find them useful.
// // TWMessageBarManager.m // // Created by Terry Worona on 5/13/13. // Copyright (c) 2013 Terry Worona. All rights reserved. //
// Quartz
// Numerics (TWMessageBarStyleSheet) CGFloat const kTWMessageBarStyleSheetMessageBarAlpha = 0.96f;
// Numerics (TWMessageView) CGFloat const kTWMessageViewBarPadding = 10.0f; CGFloat const kTWMessageViewIconSize = 36.0f; CGFloat const kTWMessageViewTextOffset = 2.0f; NSUInteger const kTWMessageViewiOS7Identifier = 7;
// Numerics (TWMessageBarManager) CGFloat const kTWMessageBarManagerDisplayDelay = 5.0f; CGFloat const kTWMessageBarManagerDismissAnimationDuration = 0.25f; CGFloat const kTWMessageBarManagerPanVelocity = 0.2f; CGFloat const kTWMessageBarManagerPanAnimationDuration = 0.0002f;
// Strings (TWMessageBarStyleSheet) NSString * const kTWMessageBarStyleSheetImageIconError = @"icon-error.png"; NSString * const kTWMessageBarStyleSheetImageIconSuccess = @"icon-success.png"; NSString * const kTWMessageBarStyleSheetImageIconInfo = @"icon-info.png";
// Fonts (TWMessageView) static UIFont kTWMessageViewTitleFont = nil; static UIFont kTWMessageViewDescriptionFont = nil;
// Colors (TWMessageView) static UIColor kTWMessageViewTitleColor = nil; static UIColor kTWMessageViewDescriptionColor = nil;
// Colors (TWDefaultMessageBarStyleSheet) static UIColor kTWDefaultMessageBarStyleSheetErrorBackgroundColor = nil; static UIColor kTWDefaultMessageBarStyleSheetSuccessBackgroundColor = nil; static UIColor kTWDefaultMessageBarStyleSheetInfoBackgroundColor = nil; static UIColor kTWDefaultMessageBarStyleSheetErrorStrokeColor = nil; static UIColor kTWDefaultMessageBarStyleSheetSuccessStrokeColor = nil; static UIColor kTWDefaultMessageBarStyleSheetInfoStrokeColor = nil;
@protocol TWMessageViewDelegate;
@interface TWMessageView : UIView
@property (nonatomic, copy) NSString titleString; @property (nonatomic, copy) NSString descriptionString;
@property (nonatomic, assign) TWMessageBarMessageType messageType;
@property (nonatomic, assign) BOOL hasCallbackOk; @property (nonatomic, strong) NSArray *callbacksOk;
@property (nonatomic, assign) BOOL hasCallbackCancel; @property (nonatomic, strong) NSArray *callbacksCancel;
@property (nonatomic, assign, getter = isHit) BOOL hit;
@property (nonatomic, assign) CGFloat duration;
@property (nonatomic, assign) UIStatusBarStyle statusBarStyle; @property (nonatomic, assign) BOOL statusBarHidden;
@property (nonatomic, weak) id delegate;
// Initializers
// Getters
// Helpers
// Notifications
@end
@protocol TWMessageViewDelegate
@interface TWDefaultMessageBarStyleSheet : NSObject
@interface TWMessageWindow : UIWindow
@interface TWMessageBarViewController : UIViewController
@interface TWMessageBarManager ()
@property (nonatomic, strong) NSMutableArray messageBarQueue; @property (nonatomic, assign, getter = isMessageVisible) BOOL messageVisible; @property (nonatomic, strong) TWMessageWindow messageWindow; @property (nonatomic, readwrite) NSArray *accessibleElements; // accessibility
// Static
// Gestures
// Master presetation
@implementation TWMessageBarManager
(void)showMessageWithTitle:(NSString )title description:(NSString )description type:(TWMessageBarMessageType)type duration:(CGFloat)duration statusBarHidden:(BOOL)statusBarHidden statusBarStyle:(UIStatusBarStyle)statusBarStyle callbackOk:(void (^)())callbackOk callbackCancel:(void (^)())callbackCancel { TWMessageView *messageView = [[TWMessageView alloc] initWithTitle:title description:description type:type]; messageView.delegate = self;
messageView.callbacksOk = callbackOk ? [NSArray arrayWithObject:callbackOk] : [NSArray array]; messageView.hasCallbackOk = callbackOk ? YES : NO;
messageView.callbacksCancel = callbackCancel ? [NSArray arrayWithObject:callbackCancel] : [NSArray array]; messageView.hasCallbackCancel = callbackCancel ? YES : NO;
messageView.duration = duration; messageView.hidden = YES;
messageView.statusBarStyle = statusBarStyle; messageView.statusBarHidden = statusBarHidden;
[[self messageWindowView] addSubview:messageView]; [[self messageWindowView] bringSubviewToFront:messageView];
[self.messageBarQueue addObject:messageView];
if (!self.messageVisible) { [self showNextMessage]; } }
(void)hideAllAnimated:(BOOL)animated { for (UIView subview in [[self messageWindowView] subviews]) { if ([subview isKindOfClass:[TWMessageView class]]) { TWMessageView currentMessageView = (TWMessageView *)subview; if (animated) { [UIView animateWithDuration:kTWMessageBarManagerDismissAnimationDuration animations:^{ currentMessageView.frame = CGRectMake(currentMessageView.frame.origin.x, -currentMessageView.frame.size.height, currentMessageView.frame.size.width, currentMessageView.frame.size.height); } completion:^(BOOL finished) { [currentMessageView removeFromSuperview]; }]; } else { [currentMessageView removeFromSuperview]; } } }
self.messageVisible = NO; [self.messageBarQueue removeAllObjects]; [NSObject cancelPreviousPerformRequestsWithTarget:self]; self.messageWindow.hidden = YES; self.messageWindow = nil; }
(void)showNextMessage { if ([self.messageBarQueue count] > 0) { self.messageVisible = YES;
TWMessageView *messageView = [self.messageBarQueue objectAtIndex:0]; [self messageBarViewController].statusBarHidden = messageView.statusBarHidden; // important to do this prior to hiding messageView.frame = CGRectMake(0, -[messageView height], [messageView width], [messageView height]); messageView.hidden = NO; [messageView setNeedsDisplay]; UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemSelected:)]; [messageView addGestureRecognizer:gest]; UISwipeGestureRecognizer *swipeGest = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(itemSelected:)]; swipeGest.direction = UISwipeGestureRecognizerDirectionUp; [messageView addGestureRecognizer:swipeGest]; if (messageView) { [self.messageBarQueue removeObject:messageView]; [self messageBarViewController].statusBarStyle = messageView.statusBarStyle; [UIView animateWithDuration:kTWMessageBarManagerDismissAnimationDuration animations:^{ [messageView setFrame:CGRectMake(messageView.frame.origin.x, messageView.frame.origin.y + [messageView height], [messageView width], [messageView height])]; // slide down }]; [self performSelector:@selector(itemSelected:) withObject:messageView afterDelay:messageView.duration]; [self generateAccessibleElementWithTitle:messageView.titleString description:messageView.descriptionString]; }
} }
(void)itemSelected:(id)sender { TWMessageView *messageView = nil; BOOL itemHit = NO;
if ([sender isKindOfClass:[UISwipeGestureRecognizer class]]) { messageView = (TWMessageView )((UIGestureRecognizer )sender).view; } else if ([sender isKindOfClass:[UIGestureRecognizer class]]) { messageView = (TWMessageView )((UIGestureRecognizer )sender).view; itemHit = YES; } else if ([sender isKindOfClass:[TWMessageView class]]) { messageView = (TWMessageView *)sender; }
if (messageView && ![messageView isHit]) { messageView.hit = YES;
[UIView animateWithDuration:kTWMessageBarManagerDismissAnimationDuration animations:^{ [messageView setFrame:CGRectMake(messageView.frame.origin.x, messageView.frame.origin.y - [messageView height], [messageView width], [messageView height])]; // slide back up } completion:^(BOOL finished) { if (itemHit) { if ([messageView.callbacksOk count] > 0) { id obj = [messageView.callbacksOk objectAtIndex:0]; if (![obj isEqual:[NSNull null]]) { ((void (^)())obj)(); } } } else { if ([messageView.callbacksCancel count] > 0) { id obj = [messageView.callbacksCancel objectAtIndex:0]; if (![obj isEqual:[NSNull null]]) { ((void (^)())obj)(); } } } self.messageVisible = NO; [messageView removeFromSuperview]; if([self.messageBarQueue count] > 0) { [self showNextMessage]; } else { self.messageWindow.hidden = YES; self.messageWindow = nil; } }];
@implementation TWMessageView
(void)initialize { if (self == [TWMessageView class]) { // Fonts kTWMessageViewTitleFont = [UIFont boldSystemFontOfSize:16.0]; kTWMessageViewDescriptionFont = [UIFont systemFontOfSize:14.0];
// Colors kTWMessageViewTitleColor = [UIColor colorWithWhite:1.0 alpha:1.0]; kTWMessageViewDescriptionColor = [UIColor colorWithWhite:1.0 alpha:1.0];
(id)initWithTitle:(NSString )title description:(NSString )description type:(TWMessageBarMessageType)type { self = [super initWithFrame:CGRectZero]; if (self) { self.backgroundColor = [UIColor clearColor]; self.clipsToBounds = NO; self.userInteractionEnabled = YES;
_titleString = title; _descriptionString = description; _messageType = type; _hasCallbackOk = NO; _hasCallbackCancel = NO; _hit = NO; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeDeviceOrientation:) name:UIDeviceOrientationDidChangeNotification object:nil];
} return self; }
(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext();
if ([self.delegate respondsToSelector:@selector(styleSheetForMessageView:)]) { id styleSheet = [self.delegate styleSheetForMessageView:self];
// background fill CGContextSaveGState(context); { if ([styleSheet respondsToSelector:@selector(backgroundColorForMessageType:)]) { [[styleSheet backgroundColorForMessageType:self.messageType] set]; CGContextFillRect(context, rect); } } CGContextRestoreGState(context); // bottom stroke CGContextSaveGState(context); { if ([styleSheet respondsToSelector:@selector(strokeColorForMessageType:)]) { CGContextBeginPath(context); CGContextMoveToPoint(context, 0, rect.size.height); CGContextSetStrokeColorWithColor(context, [styleSheet strokeColorForMessageType:self.messageType].CGColor); CGContextSetLineWidth(context, 1.0); CGContextAddLineToPoint(context, rect.size.width, rect.size.height); CGContextStrokePath(context); } } CGContextRestoreGState(context); CGFloat xOffset = kTWMessageViewBarPadding; CGFloat yOffset = kTWMessageViewBarPadding + [self statusBarOffset]; // icon CGContextSaveGState(context); { if ([styleSheet respondsToSelector:@selector(iconImageForMessageType:)]) { [[styleSheet iconImageForMessageType:self.messageType] drawInRect:CGRectMake(xOffset, yOffset, kTWMessageViewIconSize, kTWMessageViewIconSize)]; } } CGContextRestoreGState(context); yOffset -= kTWMessageViewTextOffset; xOffset += kTWMessageViewIconSize + kTWMessageViewBarPadding; CGSize titleLabelSize = [self titleSize]; CGSize descriptionLabelSize = [self descriptionSize]; if (self.titleString && !self.descriptionString) { yOffset = ceil(rect.size.height * 0.5) - ceil(titleLabelSize.height * 0.5) - kTWMessageViewTextOffset; } if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; paragraphStyle.alignment = NSTextAlignmentLeft; [[self titleColor] set]; [self.titleString drawWithRect:CGRectMake(xOffset, yOffset, titleLabelSize.width, titleLabelSize.height) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:[self titleFont], NSForegroundColorAttributeName:[self titleColor], NSParagraphStyleAttributeName:paragraphStyle} context:nil]; yOffset += titleLabelSize.height; [[self descriptionColor] set]; [self.descriptionString drawWithRect:CGRectMake(xOffset, yOffset, descriptionLabelSize.width, descriptionLabelSize.height) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:[self descriptionFont], NSForegroundColorAttributeName:[self descriptionColor], NSParagraphStyleAttributeName:paragraphStyle} context:nil]; } else { [[self titleColor] set];
[self.titleString drawInRect:CGRectMake(xOffset, yOffset, titleLabelSize.width, titleLabelSize.height) withFont:[self titleFont] lineBreakMode:NSLineBreakByTruncatingTail alignment:NSTextAlignmentLeft];
yOffset += titleLabelSize.height; [[self descriptionColor] set];
[self.descriptionString drawInRect:CGRectMake(xOffset, yOffset, descriptionLabelSize.width, descriptionLabelSize.height) withFont:[self descriptionFont] lineBreakMode:NSLineBreakByTruncatingTail alignment:NSTextAlignmentLeft];
}
(CGSize)titleSize { CGSize boundedSize = CGSizeMake([self availableWidth], CGFLOAT_MAX); CGSize titleLabelSize;
if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { NSDictionary *titleStringAttributes = [NSDictionary dictionaryWithObject:[self titleFont] forKey: NSFontAttributeName]; titleLabelSize = [self.titleString boundingRectWithSize:boundedSize options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin attributes:titleStringAttributes context:nil].size; } else {
titleLabelSize = [_titleString sizeWithFont:[self titleFont] constrainedToSize:boundedSize lineBreakMode:NSLineBreakByTruncatingTail];
return CGSizeMake(ceilf(titleLabelSize.width), ceilf(titleLabelSize.height)); }
(CGSize)descriptionSize { CGSize boundedSize = CGSizeMake([self availableWidth], CGFLOAT_MAX); CGSize descriptionLabelSize;
if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { NSDictionary *descriptionStringAttributes = [NSDictionary dictionaryWithObject:[self descriptionFont] forKey: NSFontAttributeName]; descriptionLabelSize = [self.descriptionString boundingRectWithSize:boundedSize options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin attributes:descriptionStringAttributes context:nil].size; } else {
descriptionLabelSize = [_descriptionString sizeWithFont:[self descriptionFont] constrainedToSize:boundedSize lineBreakMode:NSLineBreakByTruncatingTail];
return CGSizeMake(ceilf(descriptionLabelSize.width), ceilf(descriptionLabelSize.height)); }
(CGRect)statusBarFrame { CGRect windowFrame = NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1 ? [self orientFrame:[UIApplication sharedApplication].keyWindow.frame] : [UIApplication sharedApplication].keyWindow.frame; CGRect statusFrame = NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1 ? [self orientFrame:[UIApplication sharedApplication].statusBarFrame] : [UIApplication sharedApplication].statusBarFrame;
BOOL isLandscape = (NSFoundationVersionNumber < NSFoundationVersionNumber_iOS_8_0) && UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]); return CGRectMake(windowFrame.origin.x, windowFrame.origin.y, isLandscape? windowFrame.size.height: windowFrame.size.width, isLandscape? statusFrame.size.width: statusFrame.size.height); }
@implementation TWDefaultMessageBarStyleSheet
(void)initialize { if (self == [TWDefaultMessageBarStyleSheet class]) { // Colors (background) kTWDefaultMessageBarStyleSheetErrorBackgroundColor = [UIColor colorWithRed:1.0 green:0.611 blue:0.0 alpha:kTWMessageBarStyleSheetMessageBarAlpha]; // orange kTWDefaultMessageBarStyleSheetSuccessBackgroundColor = [UIColor colorWithRed:0.0f green:0.831f blue:0.176f alpha:kTWMessageBarStyleSheetMessageBarAlpha]; // green kTWDefaultMessageBarStyleSheetInfoBackgroundColor = [UIColor colorWithRed:0.0 green:0.482 blue:1.0 alpha:kTWMessageBarStyleSheetMessageBarAlpha]; // blue
// Colors (stroke) kTWDefaultMessageBarStyleSheetErrorStrokeColor = [UIColor colorWithRed:0.949f green:0.580f blue:0.0f alpha:1.0f]; // orange kTWDefaultMessageBarStyleSheetSuccessStrokeColor = [UIColor colorWithRed:0.0f green:0.772f blue:0.164f alpha:1.0f]; // green kTWDefaultMessageBarStyleSheetInfoStrokeColor = [UIColor colorWithRed:0.0f green:0.415f blue:0.803f alpha:1.0f]; // blue
@implementation TWMessageWindow
(UIView )hitTest:(CGPoint)point withEvent:(UIEvent )event { UIView *hitView = [super hitTest:point withEvent:event];
/*
return hitView; }
@implementation UIDevice (Additions)
@implementation TWMessageBarViewController
(void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle { _statusBarStyle = statusBarStyle;
if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { [self setNeedsStatusBarAppearanceUpdate]; } }
(void)setStatusBarHidden:(BOOL)statusBarHidden { _statusBarHidden = statusBarHidden;
If you have a feature request, please submit a pull request.
Below you can find code of you class with my minor changes (changes to .h can be done by oneself). Hope you'll find them useful.
// // TWMessageBarManager.m // // Created by Terry Worona on 5/13/13. // Copyright (c) 2013 Terry Worona. All rights reserved. //
import "TWMessageBarManager.h"
// Quartz
import <QuartzCore/QuartzCore.h>
// Numerics (TWMessageBarStyleSheet) CGFloat const kTWMessageBarStyleSheetMessageBarAlpha = 0.96f;
// Numerics (TWMessageView) CGFloat const kTWMessageViewBarPadding = 10.0f; CGFloat const kTWMessageViewIconSize = 36.0f; CGFloat const kTWMessageViewTextOffset = 2.0f; NSUInteger const kTWMessageViewiOS7Identifier = 7;
// Numerics (TWMessageBarManager) CGFloat const kTWMessageBarManagerDisplayDelay = 5.0f; CGFloat const kTWMessageBarManagerDismissAnimationDuration = 0.25f; CGFloat const kTWMessageBarManagerPanVelocity = 0.2f; CGFloat const kTWMessageBarManagerPanAnimationDuration = 0.0002f;
// Strings (TWMessageBarStyleSheet) NSString * const kTWMessageBarStyleSheetImageIconError = @"icon-error.png"; NSString * const kTWMessageBarStyleSheetImageIconSuccess = @"icon-success.png"; NSString * const kTWMessageBarStyleSheetImageIconInfo = @"icon-info.png";
// Fonts (TWMessageView) static UIFont kTWMessageViewTitleFont = nil; static UIFont kTWMessageViewDescriptionFont = nil;
// Colors (TWMessageView) static UIColor kTWMessageViewTitleColor = nil; static UIColor kTWMessageViewDescriptionColor = nil;
// Colors (TWDefaultMessageBarStyleSheet) static UIColor kTWDefaultMessageBarStyleSheetErrorBackgroundColor = nil; static UIColor kTWDefaultMessageBarStyleSheetSuccessBackgroundColor = nil; static UIColor kTWDefaultMessageBarStyleSheetInfoBackgroundColor = nil; static UIColor kTWDefaultMessageBarStyleSheetErrorStrokeColor = nil; static UIColor kTWDefaultMessageBarStyleSheetSuccessStrokeColor = nil; static UIColor kTWDefaultMessageBarStyleSheetInfoStrokeColor = nil;
@protocol TWMessageViewDelegate;
@interface TWMessageView : UIView
@property (nonatomic, copy) NSString titleString; @property (nonatomic, copy) NSString descriptionString;
@property (nonatomic, assign) TWMessageBarMessageType messageType;
@property (nonatomic, assign) BOOL hasCallbackOk; @property (nonatomic, strong) NSArray *callbacksOk;
@property (nonatomic, assign) BOOL hasCallbackCancel; @property (nonatomic, strong) NSArray *callbacksCancel;
@property (nonatomic, assign, getter = isHit) BOOL hit;
@property (nonatomic, assign) CGFloat duration;
@property (nonatomic, assign) UIStatusBarStyle statusBarStyle; @property (nonatomic, assign) BOOL statusBarHidden;
@property (nonatomic, weak) id delegate;
// Initializers
// Getters
// Helpers
// Notifications
@end
@protocol TWMessageViewDelegate
@end
@interface TWDefaultMessageBarStyleSheet : NSObject
@end
@interface TWMessageWindow : UIWindow
@end
@interface TWMessageBarViewController : UIViewController
@property (nonatomic, assign) UIStatusBarStyle statusBarStyle; @property (nonatomic, assign) BOOL statusBarHidden;
@end
@interface TWMessageBarManager ()
@property (nonatomic, strong) NSMutableArray messageBarQueue; @property (nonatomic, assign, getter = isMessageVisible) BOOL messageVisible; @property (nonatomic, strong) TWMessageWindow messageWindow; @property (nonatomic, readwrite) NSArray *accessibleElements; // accessibility
// Static
// Helpers
// Gestures
// Getters
// Master presetation
@end
@implementation TWMessageBarManager
pragma mark - Singleton
pragma mark - Static
pragma mark - Alloc/Init
pragma mark - Public
pragma mark - Master Presentation
(void)showMessageWithTitle:(NSString )title description:(NSString )description type:(TWMessageBarMessageType)type duration:(CGFloat)duration statusBarHidden:(BOOL)statusBarHidden statusBarStyle:(UIStatusBarStyle)statusBarStyle callbackOk:(void (^)())callbackOk callbackCancel:(void (^)())callbackCancel { TWMessageView *messageView = [[TWMessageView alloc] initWithTitle:title description:description type:type]; messageView.delegate = self;
messageView.callbacksOk = callbackOk ? [NSArray arrayWithObject:callbackOk] : [NSArray array]; messageView.hasCallbackOk = callbackOk ? YES : NO;
messageView.callbacksCancel = callbackCancel ? [NSArray arrayWithObject:callbackCancel] : [NSArray array]; messageView.hasCallbackCancel = callbackCancel ? YES : NO;
messageView.duration = duration; messageView.hidden = YES;
messageView.statusBarStyle = statusBarStyle; messageView.statusBarHidden = statusBarHidden;
[[self messageWindowView] addSubview:messageView]; [[self messageWindowView] bringSubviewToFront:messageView];
[self.messageBarQueue addObject:messageView];
if (!self.messageVisible) { [self showNextMessage]; } }
(void)hideAllAnimated:(BOOL)animated { for (UIView subview in [[self messageWindowView] subviews]) { if ([subview isKindOfClass:[TWMessageView class]]) { TWMessageView currentMessageView = (TWMessageView *)subview; if (animated) { [UIView animateWithDuration:kTWMessageBarManagerDismissAnimationDuration animations:^{ currentMessageView.frame = CGRectMake(currentMessageView.frame.origin.x, -currentMessageView.frame.size.height, currentMessageView.frame.size.width, currentMessageView.frame.size.height); } completion:^(BOOL finished) { [currentMessageView removeFromSuperview]; }]; } else { [currentMessageView removeFromSuperview]; } } }
self.messageVisible = NO; [self.messageBarQueue removeAllObjects]; [NSObject cancelPreviousPerformRequestsWithTarget:self]; self.messageWindow.hidden = YES; self.messageWindow = nil; }
pragma mark - Helpers
(void)showNextMessage { if ([self.messageBarQueue count] > 0) { self.messageVisible = YES;
} }
pragma mark - Gestures
(void)itemSelected:(id)sender { TWMessageView *messageView = nil; BOOL itemHit = NO;
if ([sender isKindOfClass:[UISwipeGestureRecognizer class]]) { messageView = (TWMessageView )((UIGestureRecognizer )sender).view; } else if ([sender isKindOfClass:[UIGestureRecognizer class]]) { messageView = (TWMessageView )((UIGestureRecognizer )sender).view; itemHit = YES; } else if ([sender isKindOfClass:[TWMessageView class]]) { messageView = (TWMessageView *)sender; }
if (messageView && ![messageView isHit]) { messageView.hit = YES;
} }
pragma mark - Getters
pragma mark - Setters
pragma mark - TWMessageViewDelegate
pragma mark - UIAccessibilityContainer
@end
@implementation TWMessageView
pragma mark - Alloc/Init
(void)initialize { if (self == [TWMessageView class]) { // Fonts kTWMessageViewTitleFont = [UIFont boldSystemFontOfSize:16.0]; kTWMessageViewDescriptionFont = [UIFont systemFontOfSize:14.0];
} }
(id)initWithTitle:(NSString )title description:(NSString )description type:(TWMessageBarMessageType)type { self = [super initWithFrame:CGRectZero]; if (self) { self.backgroundColor = [UIColor clearColor]; self.clipsToBounds = NO; self.userInteractionEnabled = YES;
} return self; }
pragma mark - Memory Management
pragma mark - Drawing
(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext();
if ([self.delegate respondsToSelector:@selector(styleSheetForMessageView:)]) { id styleSheet = [self.delegate styleSheetForMessageView:self];
pragma clang diagnostic push
pragma clang diagnostic ignored "-Wdeprecated-declarations"
pragma clang diagnostic pop
pragma clang diagnostic push
pragma clang diagnostic ignored "-Wdeprecated-declarations"
pragma clang diagnostic pop
} }
pragma mark - Getters
(CGSize)titleSize { CGSize boundedSize = CGSizeMake([self availableWidth], CGFLOAT_MAX); CGSize titleLabelSize;
if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { NSDictionary *titleStringAttributes = [NSDictionary dictionaryWithObject:[self titleFont] forKey: NSFontAttributeName]; titleLabelSize = [self.titleString boundingRectWithSize:boundedSize options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin attributes:titleStringAttributes context:nil].size; } else {
pragma clang diagnostic push
pragma clang diagnostic ignored "-Wdeprecated-declarations"
pragma clang diagnostic pop
}
return CGSizeMake(ceilf(titleLabelSize.width), ceilf(titleLabelSize.height)); }
(CGSize)descriptionSize { CGSize boundedSize = CGSizeMake([self availableWidth], CGFLOAT_MAX); CGSize descriptionLabelSize;
if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { NSDictionary *descriptionStringAttributes = [NSDictionary dictionaryWithObject:[self descriptionFont] forKey: NSFontAttributeName]; descriptionLabelSize = [self.descriptionString boundingRectWithSize:boundedSize options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin attributes:descriptionStringAttributes context:nil].size; } else {
pragma clang diagnostic push
pragma clang diagnostic ignored "-Wdeprecated-declarations"
pragma clang diagnostic pop
}
return CGSizeMake(ceilf(descriptionLabelSize.width), ceilf(descriptionLabelSize.height)); }
(CGRect)statusBarFrame { CGRect windowFrame = NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1 ? [self orientFrame:[UIApplication sharedApplication].keyWindow.frame] : [UIApplication sharedApplication].keyWindow.frame; CGRect statusFrame = NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1 ? [self orientFrame:[UIApplication sharedApplication].statusBarFrame] : [UIApplication sharedApplication].statusBarFrame;
BOOL isLandscape = (NSFoundationVersionNumber < NSFoundationVersionNumber_iOS_8_0) && UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]); return CGRectMake(windowFrame.origin.x, windowFrame.origin.y, isLandscape? windowFrame.size.height: windowFrame.size.width, isLandscape? statusFrame.size.width: statusFrame.size.height); }
pragma mark - Helpers
pragma mark - Notifications
@end
@implementation TWDefaultMessageBarStyleSheet
pragma mark - Alloc/Init
(void)initialize { if (self == [TWDefaultMessageBarStyleSheet class]) { // Colors (background) kTWDefaultMessageBarStyleSheetErrorBackgroundColor = [UIColor colorWithRed:1.0 green:0.611 blue:0.0 alpha:kTWMessageBarStyleSheetMessageBarAlpha]; // orange kTWDefaultMessageBarStyleSheetSuccessBackgroundColor = [UIColor colorWithRed:0.0f green:0.831f blue:0.176f alpha:kTWMessageBarStyleSheetMessageBarAlpha]; // green kTWDefaultMessageBarStyleSheetInfoBackgroundColor = [UIColor colorWithRed:0.0 green:0.482 blue:1.0 alpha:kTWMessageBarStyleSheetMessageBarAlpha]; // blue
} }
pragma mark - TWMessageBarStyleSheet
@end
@implementation TWMessageWindow
pragma mark - Touches
(UIView )hitTest:(CGPoint)point withEvent:(UIEvent )event { UIView *hitView = [super hitTest:point withEvent:event];
/*
return hitView; }
@end
@implementation UIDevice (Additions)
pragma mark - OS Helpers
@end
@implementation TWMessageBarViewController
pragma mark - Setters
(void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle { _statusBarStyle = statusBarStyle;
if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { [self setNeedsStatusBarAppearanceUpdate]; } }
(void)setStatusBarHidden:(BOOL)statusBarHidden { _statusBarHidden = statusBarHidden;
if ([[UIDevice currentDevice] tw_isRunningiOS7OrLater]) { [self setNeedsStatusBarAppearanceUpdate]; } }
pragma mark - Status Bar
@end