diff --git a/MKInfoBundle/MKInfoPanel.h b/MKInfoBundle/MKInfoPanel.h index 7736db0..99bca8c 100644 --- a/MKInfoBundle/MKInfoPanel.h +++ b/MKInfoBundle/MKInfoPanel.h @@ -20,8 +20,7 @@ #import #define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] -typedef enum MKInfoPanelType_ -{ +typedef enum { MKInfoPanelTypeInfo, MKInfoPanelTypeError } MKInfoPanelType; @@ -33,15 +32,29 @@ typedef enum MKInfoPanelType_ UIImageView *_thumbImage; UIImageView *_backgroundGradient; + + SEL _onTouched; + + id _delegate; + SEL _onFinished; + + MKInfoPanelType type_; } @property (nonatomic, assign) IBOutlet UILabel *titleLabel; @property (nonatomic, assign) IBOutlet UILabel *detailLabel; @property (nonatomic, assign) IBOutlet UIImageView *thumbImage; @property (nonatomic, assign) IBOutlet UIImageView *backgroundGradient; +@property (nonatomic, assign) SEL onTouched; +@property (nonatomic, assign) id delegate; +@property (nonatomic, assign) SEL onFinished; + ++ (MKInfoPanel *)showPanelInView:(UIView*)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle; ++ (MKInfoPanel *)showPanelInView:(UIView*)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval; -+(void) showPanelInView:(UIView*) view type:(MKInfoPanelType) type title:(NSString*) title subtitle:(NSString*) subtitle hideAfter:(NSTimeInterval) interval; ++ (MKInfoPanel *)showPanelInWindow:(UIWindow*)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle; ++ (MKInfoPanel *)showPanelInWindow:(UIWindow*)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval; -+(void) showPanelInWindow:(UIWindow*) window type:(MKInfoPanelType) type title:(NSString*) title subtitle:(NSString*) subtitle hideAfter:(NSTimeInterval) interval; +- (void)hidePanel; @end diff --git a/MKInfoBundle/MKInfoPanel.m b/MKInfoBundle/MKInfoPanel.m index 69e946a..f280b92 100644 --- a/MKInfoBundle/MKInfoPanel.m +++ b/MKInfoBundle/MKInfoPanel.m @@ -21,126 +21,180 @@ #import // Private Methods -// this should be added before implementation block -@interface MKInfoPanel (PrivateMethods) +@interface MKInfoPanel () + @property (nonatomic, assign) MKInfoPanelType type; + + (MKInfoPanel*) infoPanel; + +- (void)setup; + @end @implementation MKInfoPanel + @synthesize titleLabel = _titleLabel; @synthesize detailLabel = _detailLabel; @synthesize thumbImage = _thumbImage; @synthesize backgroundGradient = _backgroundGradient; +@synthesize onTouched = _onTouched; +@synthesize delegate = _delegate; +@synthesize onFinished = _onFinished; +@synthesize type = type_; -- (id)initWithFrame:(CGRect)frame -{ + +//////////////////////////////////////////////////////////////////////// +#pragma mark - +#pragma mark Lifecycle +//////////////////////////////////////////////////////////////////////// + +- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - // Initialization code + [self setup]; + } + return self; +} + +- (id)initWithCoder:(NSCoder *)aDecoder { + self = [super initWithCoder:aDecoder]; + if (self) { + [self setup]; } return self; } --(void) setType:(MKInfoPanelType)type -{ - if(type == MKInfoPanelTypeError) - { +- (void)dealloc { + [_delegate performSelector:_onFinished]; + + [super dealloc]; +} + +//////////////////////////////////////////////////////////////////////// +#pragma mark - +#pragma mark Setter/Getter +//////////////////////////////////////////////////////////////////////// + +-(void)setType:(MKInfoPanelType)type { + if(type == MKInfoPanelTypeError) { self.backgroundGradient.image = [[UIImage imageNamed:@"Red"] stretchableImageWithLeftCapWidth:1 topCapHeight:5]; self.titleLabel.font = [UIFont boldSystemFontOfSize:14]; self.detailLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:14]; self.thumbImage.image = [UIImage imageNamed:@"Warning"]; - self.detailLabel.textColor = RGBA(255, 140, 140, 0.6); - + self.detailLabel.textColor = [UIColor colorWithRed:1.f green:0.651f blue:0.651f alpha:1.f]; } - else if(type == MKInfoPanelTypeInfo) - { + + else if(type == MKInfoPanelTypeInfo) { self.backgroundGradient.image = [[UIImage imageNamed:@"Blue"] stretchableImageWithLeftCapWidth:1 topCapHeight:5]; self.titleLabel.font = [UIFont boldSystemFontOfSize:15]; self.thumbImage.image = [UIImage imageNamed:@"Tick"]; self.detailLabel.textColor = RGBA(210, 210, 235, 1.0); } - } -+(MKInfoPanel*) infoPanel -{ - MKInfoPanel *panel = (MKInfoPanel*) [[[UINib nibWithNibName:@"MKInfoPanel" bundle:nil] - instantiateWithOwner:self options:nil] objectAtIndex:0]; - - CATransition *transition = [CATransition animation]; - transition.duration = 0.25; - transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; - transition.type = kCATransitionPush; - transition.subtype = kCATransitionFromBottom; - [panel.layer addAnimation:transition forKey:nil]; - - return panel; +//////////////////////////////////////////////////////////////////////// +#pragma mark - +#pragma mark Show/Hide +//////////////////////////////////////////////////////////////////////// + ++ (MKInfoPanel *)showPanelInView:(UIView *)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle { + return [self showPanelInView:view type:type title:title subtitle:subtitle hideAfter:-1]; } -+(void) showPanelInView:(UIView*) view type:(MKInfoPanelType) type title:(NSString*) title subtitle:(NSString*) subtitle hideAfter:(NSTimeInterval) interval -{ ++(MKInfoPanel *)showPanelInView:(UIView *)view type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval { MKInfoPanel *panel = [MKInfoPanel infoPanel]; - [panel setType:type]; + CGFloat panelHeight = 50; // panel height when no subtitle set + + panel.type = type; panel.titleLabel.text = title; - if(subtitle) - { + + if(subtitle) { panel.detailLabel.text = subtitle; - } - else - { + [panel.detailLabel sizeToFit]; + + panelHeight = MAX(CGRectGetMaxY(panel.thumbImage.frame), CGRectGetMaxY(panel.detailLabel.frame)); + panelHeight += 10.f; // padding at bottom + } else { panel.detailLabel.hidden = YES; - panel.frame = CGRectMake(0, 0, 320, 50); panel.thumbImage.frame = CGRectMake(15, 5, 35, 35); panel.titleLabel.frame = CGRectMake(57, 12, 240, 21); - } + // update frame of panel + panel.frame = CGRectMake(0, 0, view.bounds.size.width, panelHeight); [view addSubview:panel]; - [panel performSelector:@selector(hidePanel) withObject:view afterDelay:interval]; + + if (interval > 0) { + [panel performSelector:@selector(hidePanel) withObject:view afterDelay:interval]; + } + + return panel; } -+(void) showPanelInWindow:(UIWindow*) window type:(MKInfoPanelType) type title:(NSString*) title subtitle:(NSString*) subtitle hideAfter:(NSTimeInterval) interval -{ - MKInfoPanel *panel = [MKInfoPanel infoPanel]; - [panel setType:type]; - panel.titleLabel.text = title; - if(subtitle) - { - panel.detailLabel.text = subtitle; - } - else - { - panel.detailLabel.hidden = YES; - panel.frame = CGRectMake(0, 20, 320, 50); - panel.thumbImage.frame = CGRectMake(15, 5, 35, 35); - panel.titleLabel.frame = CGRectMake(57, 12, 240, 21); - ++ (MKInfoPanel *)showPanelInWindow:(UIWindow *)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle { + return [self showPanelInWindow:window type:type title:title subtitle:subtitle hideAfter:-1]; +} + ++(MKInfoPanel *)showPanelInWindow:(UIWindow *)window type:(MKInfoPanelType)type title:(NSString *)title subtitle:(NSString *)subtitle hideAfter:(NSTimeInterval)interval { + MKInfoPanel *panel = [self showPanelInView:window type:type title:title subtitle:subtitle hideAfter:interval]; + + if (![UIApplication sharedApplication].statusBarHidden) { + CGRect frame = panel.frame; + frame.origin.y += [UIApplication sharedApplication].statusBarFrame.size.height; + panel.frame = frame; } - [window addSubview:panel]; - [panel performSelector:@selector(hidePanel) withObject:window afterDelay:interval]; + return panel; } --(void) hidePanel -{ +-(void)hidePanel { + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + CATransition *transition = [CATransition animation]; transition.duration = 0.25; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.type = kCATransitionPush; transition.subtype = kCATransitionFromTop; [self.layer addAnimation:transition forKey:nil]; - self.frame = CGRectMake(0, -self.frame.size.height, 320, self.frame.size.height); + self.frame = CGRectMake(0, -self.frame.size.height, self.frame.size.width, self.frame.size.height); [self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.25]; } -- (void)dealloc -{ - [super dealloc]; +//////////////////////////////////////////////////////////////////////// +#pragma mark - +#pragma mark Touch Recognition +//////////////////////////////////////////////////////////////////////// + +-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { + [self performSelector:_onTouched]; +} + +//////////////////////////////////////////////////////////////////////// +#pragma mark - +#pragma mark Private +//////////////////////////////////////////////////////////////////////// + ++(MKInfoPanel *)infoPanel { + MKInfoPanel *panel = (MKInfoPanel*) [[[UINib nibWithNibName:@"MKInfoPanel" bundle:nil] + instantiateWithOwner:self options:nil] objectAtIndex:0]; + + CATransition *transition = [CATransition animation]; + transition.duration = 0.25; + transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; + transition.type = kCATransitionPush; + transition.subtype = kCATransitionFromBottom; + [panel.layer addAnimation:transition forKey:nil]; + + return panel; +} + +- (void)setup { + self.onTouched = @selector(hidePanel); + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; } @end diff --git a/MKInfoBundle/MKInfoPanel.xib b/MKInfoBundle/MKInfoPanel.xib index d1e6c9d..14f4094 100644 --- a/MKInfoBundle/MKInfoPanel.xib +++ b/MKInfoBundle/MKInfoPanel.xib @@ -1,14 +1,14 @@ - 1056 + 1280 10J869 - 1306 + 1864 1038.35 461.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 301 + 865 YES @@ -22,11 +22,8 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin - YES - - YES - - + PluginDependencyRecalculationVersion + YES @@ -46,7 +43,7 @@ 274 - {320, 70} + {320, 66} @@ -60,7 +57,7 @@ 292 - {{72, 5}, {240, 21}} + {{57, 4}, {240, 21}} @@ -70,11 +67,6 @@ NO IBCocoaTouchFramework Network Failure - - Helvetica-Bold - 15 - 16 - 3 MQA @@ -86,13 +78,25 @@ 1 10 + + Helvetica-Bold + Helvetica + 2 + 15 + + + Helvetica-Bold + 15 + 16 + 292 - {{72, 22}, {240, 43}} + {{57, 25}, {251, 32}} + NO YES @@ -100,11 +104,6 @@ NO IBCocoaTouchFramework Check your internet connection and try again later - - HelveticaNeue - 14 - 16 - 1 MSAwLjU0OTAxOTYwNzggMC41NDkwMTk2MDc4IDAuNgA @@ -113,12 +112,23 @@ 1 NO 10 - 2 + 0 + + HelveticaNeue + Helvetica Neue + 0 + 14 + + + HelveticaNeue-Medium + 14 + 16 + 256 - {{15, 10}, {50, 50}} + {{12, 8}, {37, 34}} @@ -126,7 +136,7 @@ IBCocoaTouchFramework - {320, 70} + {320, 66} @@ -179,7 +189,9 @@ YES 0 - + + YES + @@ -189,9 +201,9 @@ YES - + @@ -232,9 +244,10 @@ YES YES + -1.IBPluginDependency -2.CustomClassName + -2.IBPluginDependency 1.CustomClassName - 1.IBEditorWindowLastContentRect 1.IBPluginDependency 3.IBPluginDependency 4.IBPluginDependency @@ -243,9 +256,10 @@ YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin MKInfoPanel - {{354, 412}, {320, 480}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -334,6 +348,6 @@ YES 3 - 301 + 865 diff --git a/MKInfoBundle/Tick.png b/MKInfoBundle/Tick.png index 1fcb2ca..1068a8b 100644 Binary files a/MKInfoBundle/Tick.png and b/MKInfoBundle/Tick.png differ diff --git a/MKInfoBundle/Tick@2x.png b/MKInfoBundle/Tick@2x.png index fe310cc..5a84f90 100644 Binary files a/MKInfoBundle/Tick@2x.png and b/MKInfoBundle/Tick@2x.png differ diff --git a/MKInfoBundle/Warning.png b/MKInfoBundle/Warning.png index 732c634..bbeebd0 100644 Binary files a/MKInfoBundle/Warning.png and b/MKInfoBundle/Warning.png differ diff --git a/MKInfoBundle/Warning@2x.png b/MKInfoBundle/Warning@2x.png index 31feca7..fe9710a 100644 Binary files a/MKInfoBundle/Warning@2x.png and b/MKInfoBundle/Warning@2x.png differ