Permalink
Browse files

Merge pull request #4 from myell0w/master

Various Tweeks!
  • Loading branch information...
2 parents 1d66e5e + 5a1da71 commit c33bbbef6f346c722c6c92b86d0ae5e593e69833 @MugunthKumar MugunthKumar committed Jun 26, 2011
@@ -20,8 +20,7 @@
#import <UIKit/UIKit.h>
#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
@@ -21,126 +21,180 @@
#import <QuartzCore/QuartzCore.h>
// 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
Oops, something went wrong.

0 comments on commit c33bbbe

Please sign in to comment.