Permalink
Browse files

added option to use blocks instead of the delegate

  • Loading branch information...
1 parent 9b787df commit 47a40932753d04fb762a54d071fb3b68f457a2b5 @barrettj barrettj committed Jan 11, 2012
View
7 UAModalPanel.xcodeproj/project.pbxproj
@@ -53,11 +53,11 @@
E64F521E14BA98FA009CB18D /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/UAViewController_iPad.xib; sourceTree = "<group>"; };
E64F522614BA9AC1009CB18D /* UARoundedRectView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UARoundedRectView.h; sourceTree = "<group>"; };
E64F522714BA9AC1009CB18D /* UARoundedRectView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UARoundedRectView.m; sourceTree = "<group>"; };
- E64F522814BA9AC1009CB18D /* UAModalPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; path = UAModalPanel.h; sourceTree = "<group>"; };
+ E64F522814BA9AC1009CB18D /* UAModalPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UAModalPanel.h; sourceTree = "<group>"; };
E64F522914BA9AC1009CB18D /* UAModalPanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UAModalPanel.m; sourceTree = "<group>"; };
- E64F522A14BA9AC1009CB18D /* UATitledModalPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; path = UATitledModalPanel.h; sourceTree = "<group>"; };
+ E64F522A14BA9AC1009CB18D /* UATitledModalPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UATitledModalPanel.h; sourceTree = "<group>"; };
E64F522B14BA9AC1009CB18D /* UATitledModalPanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UATitledModalPanel.m; sourceTree = "<group>"; };
- E64F522F14BA9B1F009CB18D /* UAExampleModalPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; path = UAExampleModalPanel.h; sourceTree = "<group>"; };
+ E64F522F14BA9B1F009CB18D /* UAExampleModalPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UAExampleModalPanel.h; sourceTree = "<group>"; };
E64F523014BA9B1F009CB18D /* UAExampleModalPanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UAExampleModalPanel.m; sourceTree = "<group>"; };
E64F523214BA9B6C009CB18D /* close.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = close.png; sourceTree = "<group>"; };
E64F523314BA9B6C009CB18D /* close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close@2x.png"; sourceTree = "<group>"; };
@@ -186,6 +186,7 @@
E64F51F814BA98FA009CB18D /* Project object */ = {
isa = PBXProject;
attributes = {
+ LastUpgradeCheck = 0420;
ORGANIZATIONNAME = "Urban Apps";
};
buildConfigurationList = E64F51FB14BA98FA009CB18D /* Build configuration list for PBXProject "UAModalPanel" */;
View
8 UAModalPanel/UAModalPanel.h
@@ -9,6 +9,11 @@
#import <Foundation/Foundation.h>
#import "UARoundedRectView.h"
+@class UAModalPanel;
+
+typedef void (^UAModalDisplayPanelEvent)(UAModalPanel* panel);
+typedef void (^UAModalDisplayPanelAnimationComplete)(BOOL finished);
+
@interface UAModalPanel : UIView {
id delegate;
@@ -51,9 +56,12 @@
// Shows the bounce animation. Default = YES
@property (nonatomic, assign) BOOL shouldBounce;
+@property (readwrite, copy) UAModalDisplayPanelEvent onClosePressed;
+
- (void)show;
- (void)showFromPoint:(CGPoint)point;
- (void)hideWithDelegate:(id)del selector:(SEL)sel;
+- (void)hideWithOnComplete:(UAModalDisplayPanelAnimationComplete)onComplete;
- (CGRect)roundedRectFrame;
- (CGRect)closeButtonFrame;
View
21 UAModalPanel/UAModalPanel.m
@@ -23,6 +23,7 @@ @implementation UAModalPanel
@synthesize roundedRect, closeButton, delegate, contentView, contentContainer;
@synthesize innerMargin, outerMargin, cornerRadius, borderWidth, borderColor, contentColor, shouldBounce;
+@synthesize onClosePressed;
- (void)calculateInnerFrame {
//adjust the popup frame here for iPad if it is too big.
@@ -180,6 +181,9 @@ - (void)closePressed:(id)sender {
if (delegate && [delegate respondsToSelector:@selector(removeModalView)]) {
[delegate performSelector:@selector(removeModalView)];
}
+
+ if (self.onClosePressed)
+ self.onClosePressed(self);
}
- (void)showAnimationStarting {}; //subcalsses override
@@ -260,4 +264,21 @@ - (void)hideWithDelegate:(id)del selector:(SEL)sel {
}
+- (void)hideWithOnComplete:(UAModalDisplayPanelAnimationComplete)onComplete {
+ // Hide the view right away
+ [UIView animateWithDuration:0.3
+ animations:^{
+ self.alpha = 0;
+ if (startEndPoint.x != CGPointZero.x || startEndPoint.y != CGPointZero.y) {
+ self.contentContainer.center = startEndPoint;
+ }
+ self.contentContainer.transform = CGAffineTransformMakeScale(0.0001, 0.0001);
+ }
+ completion:^(BOOL finished){
+ if (onComplete)
+ onComplete(finished);
+ }];
+}
+
+
@end
View
25 UAModalPanel/UAViewController.m
@@ -6,6 +6,8 @@
// Copyright (c) 2012 Urban Apps. All rights reserved.
//
+#define USE_BLOCKS
+
#import "UAViewController.h"
#import "UAExampleModalPanel.h"
@@ -42,8 +44,20 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (IBAction)showModalPanel:(id)sender {
self.currentPanel = [[[UAExampleModalPanel alloc] initWithFrame:self.view.bounds title:[(UIButton *)sender titleForState:UIControlStateNormal]] autorelease];
- self.currentPanel.delegate = self;
-
+
+#ifdef USE_BLOCKS
+ self.currentPanel.onClosePressed = ^(UAModalPanel* panel) {
+ [panel hideWithOnComplete:^(BOOL finished) {
+ [panel removeFromSuperview];
+
+ if (panel == self.currentPanel) {
+ self.currentPanel = nil;
+ }
+ }];
+ };
+#else
+ self.currentPanel.delegate = self;
+#endif
// Show the defaults mostly, but once in awhile show a funky one
if (arc4random() % 5 == 4) {
@@ -93,8 +107,11 @@ - (IBAction)showModalPanel:(id)sender {
[self.currentPanel showFromPoint:[sender center]];
}
+
#pragma mark - UAModalDisplayPanelViewDelegate
+#ifndef USE_BLOCKS
+
- (void)removeModalView {
if (self.currentPanel) {
[self.currentPanel hideWithDelegate:self selector:@selector(removeModal)];
@@ -107,4 +124,8 @@ - (void)removeModal {
self.currentPanel = nil;
}
}
+
+#endif
+
+
@end

0 comments on commit 47a4093

Please sign in to comment.