Permalink
Browse files

Decoupled some methods that use private methods of UIBarButtonItem.

  • Loading branch information...
1 parent f1f915e commit e9f52a277e61823f0861b1c64f98be5bc950a135 @sonsongithub committed Oct 8, 2011
@@ -7,12 +7,13 @@
objects = {
/* Begin PBXBuildFile section */
+ 1410EF4F144070F600C034A5 /* SNPopupView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1410EF4E144070F600C034A5 /* SNPopupView.m */; };
+ 1410EF521440711D00C034A5 /* SNPopupView+UsingPrivateMethod.m in Sources */ = {isa = PBXBuildFile; fileRef = 1410EF511440711D00C034A5 /* SNPopupView+UsingPrivateMethod.m */; };
1427AFDF127F02840082F84D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1427AFDE127F02840082F84D /* QuartzCore.framework */; };
143F9FFF139756270008ACE0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 143F9FF5139756270008ACE0 /* main.m */; };
143FA001139756270008ACE0 /* PopupViewTest-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 143F9FF8139756270008ACE0 /* PopupViewTest-Info.plist */; };
143FA002139756270008ACE0 /* PopupViewTestAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 143F9FFA139756270008ACE0 /* PopupViewTestAppDelegate.m */; };
143FA003139756270008ACE0 /* PopupViewTestViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 143F9FFC139756270008ACE0 /* PopupViewTestViewController.m */; };
- 143FA0071397562D0008ACE0 /* SNPopupView.m in Sources */ = {isa = PBXBuildFile; fileRef = 143FA0061397562D0008ACE0 /* SNPopupView.m */; };
14B7E42313BD9DB5007C8935 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 14B7E42213BD9DB5007C8935 /* MainWindow-iPad.xib */; };
14FDABA013977B3E008BF9D5 /* 2tchSmall.png in Resources */ = {isa = PBXBuildFile; fileRef = 14FDAB9713977B3E008BF9D5 /* 2tchSmall.png */; };
14FDABA113977B3E008BF9D5 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 14FDAB9913977B3E008BF9D5 /* Default.png */; };
@@ -28,6 +29,10 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 1410EF4D144070F600C034A5 /* SNPopupView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SNPopupView.h; sourceTree = "<group>"; };
+ 1410EF4E144070F600C034A5 /* SNPopupView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SNPopupView.m; sourceTree = "<group>"; };
+ 1410EF501440711D00C034A5 /* SNPopupView+UsingPrivateMethod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SNPopupView+UsingPrivateMethod.h"; sourceTree = "<group>"; };
+ 1410EF511440711D00C034A5 /* SNPopupView+UsingPrivateMethod.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SNPopupView+UsingPrivateMethod.m"; sourceTree = "<group>"; };
1427AFDE127F02840082F84D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
143F9FF5139756270008ACE0 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = PopupViewTest/main.m; sourceTree = SOURCE_ROOT; };
143F9FF7139756270008ACE0 /* PopupViewTest_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PopupViewTest_Prefix.pch; path = PopupViewTest/PopupViewTest_Prefix.pch; sourceTree = SOURCE_ROOT; };
@@ -36,8 +41,6 @@
143F9FFA139756270008ACE0 /* PopupViewTestAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PopupViewTestAppDelegate.m; path = PopupViewTest/PopupViewTestAppDelegate.m; sourceTree = SOURCE_ROOT; };
143F9FFB139756270008ACE0 /* PopupViewTestViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PopupViewTestViewController.h; path = PopupViewTest/PopupViewTestViewController.h; sourceTree = SOURCE_ROOT; };
143F9FFC139756270008ACE0 /* PopupViewTestViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PopupViewTestViewController.m; path = PopupViewTest/PopupViewTestViewController.m; sourceTree = SOURCE_ROOT; };
- 143FA0051397562D0008ACE0 /* SNPopupView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SNPopupView.h; sourceTree = "<group>"; };
- 143FA0061397562D0008ACE0 /* SNPopupView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SNPopupView.m; sourceTree = "<group>"; };
14B7E42213BD9DB5007C8935 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "PopupViewTest/Resources/iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; };
14FDAB9713977B3E008BF9D5 /* 2tchSmall.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 2tchSmall.png; sourceTree = "<group>"; };
14FDAB9913977B3E008BF9D5 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
@@ -125,8 +128,10 @@
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
- 143FA0051397562D0008ACE0 /* SNPopupView.h */,
- 143FA0061397562D0008ACE0 /* SNPopupView.m */,
+ 1410EF4D144070F600C034A5 /* SNPopupView.h */,
+ 1410EF4E144070F600C034A5 /* SNPopupView.m */,
+ 1410EF501440711D00C034A5 /* SNPopupView+UsingPrivateMethod.h */,
+ 1410EF511440711D00C034A5 /* SNPopupView+UsingPrivateMethod.m */,
080E96DDFE201D6D7F000001 /* Classes */,
14FDAB9613977B3E008BF9D5 /* Resources */,
14B7E42113BD9DB1007C8935 /* iPad */,
@@ -219,7 +224,8 @@
143F9FFF139756270008ACE0 /* main.m in Sources */,
143FA002139756270008ACE0 /* PopupViewTestAppDelegate.m in Sources */,
143FA003139756270008ACE0 /* PopupViewTestViewController.m in Sources */,
- 143FA0071397562D0008ACE0 /* SNPopupView.m in Sources */,
+ 1410EF4F144070F600C034A5 /* SNPopupView.m in Sources */,
+ 1410EF521440711D00C034A5 /* SNPopupView+UsingPrivateMethod.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -31,6 +31,7 @@
#import <UIKit/UIKit.h>
#import "SNPopupView.h"
+#import "SNPopupView+UsingPrivateMethod.h"
@interface PopupViewTestViewController : UIViewController <SNPopupViewModalDelegate> {
SNPopupView *popup;
@@ -0,0 +1,41 @@
+/*
+ * PopupView
+ * SNPopupView+UsingPrivateMethod.h
+ *
+ * Copyright (c) Yuichi YOSHIDA, 11/10/10.
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materia
+ * ls provided with the distribution.
+ * - Neither the name of the "Yuichi Yoshida" nor the names of its contributors may be u
+ * sed to endorse or promote products derived from this software without specific prior
+ * written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY E
+ * XPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES O
+ * F MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SH
+ * ALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENT
+ * AL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROC
+ * UREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS I
+ * NTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRI
+ * CT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF T
+ * HE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SNPopupView.h"
+
+@interface SNPopupView(UsingPrivateMethod)
+
+- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView;
+- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated;
+
+- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView;
+- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated;
+
+@end
@@ -0,0 +1,91 @@
+/*
+ * PopupView
+ * SNPopupView+UsingPrivateMethod.m
+ *
+ * Copyright (c) Yuichi YOSHIDA, 11/10/10.
+ * All rights reserved.
+ *
+ * BSD License
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materia
+ * ls provided with the distribution.
+ * - Neither the name of the "Yuichi Yoshida" nor the names of its contributors may be u
+ * sed to endorse or promote products derived from this software without specific prior
+ * written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY E
+ * XPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES O
+ * F MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SH
+ * ALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENT
+ * AL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROC
+ * UREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS I
+ * NTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRI
+ * CT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF T
+ * HE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SNPopupView+UsingPrivateMethod.h"
+
+@interface SNPopupView(UsingPrivateMethod_Private)
+- (void)createAndAttachTouchPeekView;
+@end
+
+@implementation SNPopupView(UsingPrivateMethod)
+
+- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView {
+ animatedWhenAppering = YES;
+ [self createAndAttachTouchPeekView];
+ [self showFromBarButtonItem:barButtonItem inView:[[UIApplication sharedApplication] keyWindow]];
+}
+
+- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated {
+ animatedWhenAppering = animated;
+ [self createAndAttachTouchPeekView];
+ [self showFromBarButtonItem:barButtonItem inView:[[UIApplication sharedApplication] keyWindow] animated:animated];
+}
+
+- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView {
+ [self showFromBarButtonItem:barButtonItem inView:inView animated:YES];
+}
+
+- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated {
+
+ if(![barButtonItem respondsToSelector:@selector(view)]) {
+ // error
+ return;
+ }
+
+ UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];
+ UIView *targetSuperview = [targetView superview];
+
+ BOOL isOnNavigationBar = YES;
+
+ if ([targetSuperview isKindOfClass:[UINavigationBar class]]) {
+ isOnNavigationBar = YES;
+ }
+ else if ([targetSuperview isKindOfClass:[UIToolbar class]]) {
+ isOnNavigationBar = NO;
+ }
+ else {
+ // error
+ return;
+ }
+
+ CGRect rect = [targetSuperview convertRect:targetView.frame toView:inView];
+
+ CGPoint p;
+ p.x = rect.origin.x + (int)rect.size.width/2;
+
+ if (isOnNavigationBar)
+ p.y = rect.origin.y + rect.size.height + BAR_BUTTON_ITEM_UPPER_MARGIN;
+ else
+ p.y = rect.origin.y - BAR_BUTTON_ITEM_BOTTOM_MARGIN;
+
+ [self showAtPoint:p inView:inView animated:animated];
+}
+
+@end
View
@@ -30,6 +30,22 @@
#import <UIKit/UIKit.h>
+#define SHADOW_OFFSET CGSizeMake(10, 10)
+#define CONTENT_OFFSET CGSizeMake(10, 10)
+#define POPUP_ROOT_SIZE CGSizeMake(20, 10)
+
+#define HORIZONTAL_SAFE_MARGIN 30
+
+#define POPUP_ANIMATION_DURATION 0.3
+#define DISMISS_ANIMATION_DURATION 0.2
+
+#define DEFAULT_TITLE_SIZE 20
+
+#define ALPHA 0.6
+
+#define BAR_BUTTON_ITEM_UPPER_MARGIN 10
+#define BAR_BUTTON_ITEM_BOTTOM_MARGIN 5
+
@class TouchPeekView;
typedef enum {
@@ -90,13 +106,9 @@ typedef enum {
- (void)showAtPoint:(CGPoint)p inView:(UIView*)inView;
- (void)showAtPoint:(CGPoint)p inView:(UIView*)inView animated:(BOOL)animated;
-- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView;
-- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated;
- (void)presentModalAtPoint:(CGPoint)p inView:(UIView*)inView;
- (void)presentModalAtPoint:(CGPoint)p inView:(UIView*)inView animated:(BOOL)animated;
-- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView;
-- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated;
- (void)dismiss;
- (void)dismiss:(BOOL)animtaed;
View
@@ -32,22 +32,6 @@
#import <QuartzCore/QuartzCore.h>
-#define SHADOW_OFFSET CGSizeMake(10, 10)
-#define CONTENT_OFFSET CGSizeMake(10, 10)
-#define POPUP_ROOT_SIZE CGSizeMake(20, 10)
-
-#define HORIZONTAL_SAFE_MARGIN 30
-
-#define POPUP_ANIMATION_DURATION 0.3
-#define DISMISS_ANIMATION_DURATION 0.2
-
-#define DEFAULT_TITLE_SIZE 20
-
-#define ALPHA 0.6
-
-#define BAR_BUTTON_ITEM_UPPER_MARGIN 10
-#define BAR_BUTTON_ITEM_BOTTOM_MARGIN 5
-
@interface TouchPeekView : UIView {
SNPopupView *delegate;
}
@@ -194,60 +178,8 @@ - (void)presentModalAtPoint:(CGPoint)p inView:(UIView*)inView animated:(BOOL)ani
[self showAtPoint:[inView convertPoint:p toView:[[UIApplication sharedApplication] keyWindow]] inView:[[UIApplication sharedApplication] keyWindow] animated:animated];
}
-- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView {
- animatedWhenAppering = YES;
- [self createAndAttachTouchPeekView];
- [self showFromBarButtonItem:barButtonItem inView:[[UIApplication sharedApplication] keyWindow]];
-}
-
-- (void)presentModalFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated {
- animatedWhenAppering = animated;
- [self createAndAttachTouchPeekView];
- [self showFromBarButtonItem:barButtonItem inView:[[UIApplication sharedApplication] keyWindow] animated:animated];
-}
-
#pragma mark - Show as normal view
-- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView {
- [self showFromBarButtonItem:barButtonItem inView:inView animated:YES];
-}
-
-- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated {
-
- if(![barButtonItem respondsToSelector:@selector(view)]) {
- // error
- return;
- }
-
- UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];
- UIView *targetSuperview = [targetView superview];
-
- BOOL isOnNavigationBar = YES;
-
- if ([targetSuperview isKindOfClass:[UINavigationBar class]]) {
- isOnNavigationBar = YES;
- }
- else if ([targetSuperview isKindOfClass:[UIToolbar class]]) {
- isOnNavigationBar = NO;
- }
- else {
- // error
- return;
- }
-
- CGRect rect = [targetSuperview convertRect:targetView.frame toView:inView];
-
- CGPoint p;
- p.x = rect.origin.x + (int)rect.size.width/2;
-
- if (isOnNavigationBar)
- p.y = rect.origin.y + rect.size.height + BAR_BUTTON_ITEM_UPPER_MARGIN;
- else
- p.y = rect.origin.y - BAR_BUTTON_ITEM_BOTTOM_MARGIN;
-
- [self showAtPoint:p inView:inView animated:animated];
-}
-
- (void)showAtPoint:(CGPoint)p inView:(UIView*)inView {
[self showAtPoint:p inView:inView animated:NO];
}

0 comments on commit e9f52a2

Please sign in to comment.