Browse files

Merge pull request #23 from yfme/master

Support both ARC and non-ARC
  • Loading branch information...
2 parents 898a824 + a13139b commit 2aa7aeafed8fbcd8983727de127cebb4545a2885 @ocrickard ocrickard committed Feb 26, 2013
Showing with 100 additions and 43 deletions.
  1. +6 −0 .gitignore
  2. +56 −5 PopoverView/PopoverView.h
  3. +38 −38 PopoverView/PopoverView.m
View
6 .gitignore
@@ -1 +1,7 @@
build/
+
+.DS_Store
+
+*.xcuserstate
+
+*.xcscheme
View
61 PopoverView/PopoverView.h
@@ -8,6 +8,57 @@
#import <UIKit/UIKit.h>
+
+/**************** Support both ARC and non-ARC ********************/
+
+#ifndef SUPPORT_ARC
+#define SUPPORT_ARC
+
+#if __has_feature(objc_arc_weak) //objc_arc_weak
+#define WEAK weak
+#define __WEAK __weak
+#define STRONG strong
+
+#define AUTORELEASE self
+#define RELEASE self
+#define RETAIN self
+#define CFTYPECAST(exp) (__bridge exp)
+#define TYPECAST(exp) (__bridge_transfer exp)
+#define CFRELEASE(exp) CFRelease(exp)
+#define DEALLOC self
+
+#elif __has_feature(objc_arc) //objc_arc
+#define WEAK unsafe_unretained
+#define __WEAK __unsafe_unretained
+#define STRONG strong
+
+#define AUTORELEASE self
+#define RELEASE self
+#define RETAIN self
+#define CFTYPECAST(exp) (__bridge exp)
+#define TYPECAST(exp) (__bridge_transfer exp)
+#define CFRELEASE(exp) CFRelease(exp)
+#define DEALLOC self
+
+#else //none
+#define WEAK assign
+#define __WEAK
+#define STRONG retain
+
+#define AUTORELEASE autorelease
+#define RELEASE release
+#define RETAIN retain
+#define CFTYPECAST(exp) (exp)
+#define TYPECAST(exp) (exp)
+#define CFRELEASE(exp) CFRelease(exp)
+#define DEALLOC dealloc
+
+#endif
+#endif
+
+/******************************************************************/
+
+
@class PopoverView;
@protocol PopoverViewDelegate <NSObject>
@@ -29,7 +80,7 @@
BOOL above;
- id<PopoverViewDelegate> delegate;
+ __WEAK id<PopoverViewDelegate> delegate;
UIView *parentView;
@@ -49,13 +100,13 @@
BOOL showDividerRects;
}
-@property (nonatomic, retain) UIView *titleView;
+@property (nonatomic, STRONG) UIView *titleView;
-@property (nonatomic, retain) UIView *contentView;
+@property (nonatomic, STRONG) UIView *contentView;
-@property (nonatomic, retain) NSArray *subviewsArray;
+@property (nonatomic, STRONG) NSArray *subviewsArray;
-@property (nonatomic, assign) id<PopoverViewDelegate> delegate;
+@property (nonatomic, WEAK) id<PopoverViewDelegate> delegate;
#pragma mark - Class Static Showing Methods
View
76 PopoverView/PopoverView.m
@@ -25,79 +25,79 @@ + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTex
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withText:text];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withText:(NSString *)text delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withTitle:title withText:text];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withViewArray:(NSArray *)viewArray delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withViewArray:viewArray];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withViewArray:(NSArray *)viewArray delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withTitle:title withViewArray:viewArray];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withStringArray:stringArray];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withStringArray:(NSArray *)stringArray delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withTitle:title withStringArray:stringArray];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray withImageArray:(NSArray *)imageArray delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withStringArray:stringArray withImageArray:imageArray];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withStringArray:(NSArray *)stringArray withImageArray:(NSArray *)imageArray delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withTitle:title withStringArray:stringArray withImageArray:imageArray];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withContentView:(UIView *)cView delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withTitle:title withContentView:cView];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
+ (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withContentView:(UIView *)cView delegate:(id<PopoverViewDelegate>)delegate {
PopoverView *popoverView = [[PopoverView alloc] initWithFrame:CGRectZero];
[popoverView showAtPoint:point inView:view withContentView:cView];
popoverView.delegate = delegate;
- [popoverView release];
+ [popoverView RELEASE];
return popoverView;
}
@@ -124,14 +124,14 @@ - (void)dealloc
self.subviewsArray = nil;
if (dividerRects) {
- [dividerRects release];
+ [dividerRects RELEASE];
dividerRects = nil;
}
self.contentView = nil;
self.titleView = nil;
- [super dealloc];
+ [super DEALLOC];
}
@@ -172,7 +172,7 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withText:(NSString *)te
textView.textColor = kTextColor;
textView.text = text;
- [self showAtPoint:point inView:view withViewArray:[NSArray arrayWithObject:[textView autorelease]]];
+ [self showAtPoint:point inView:view withViewArray:[NSArray arrayWithObject:[textView AUTORELEASE]]];
}
- (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withText:(NSString *)text
@@ -191,7 +191,7 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t
textView.textColor = kTextColor;
textView.text = text;
- [self showAtPoint:point inView:view withTitle:title withViewArray:[NSArray arrayWithObject:[textView autorelease]]];
+ [self showAtPoint:point inView:view withTitle:title withViewArray:[NSArray arrayWithObject:[textView AUTORELEASE]]];
}
- (void)showAtPoint:(CGPoint)point inView:(UIView *)view withViewArray:(NSArray *)viewArray
@@ -261,7 +261,7 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withViewArray:(NSArray
self.subviewsArray = viewArray;
- [self showAtPoint:point inView:view withContentView:[container autorelease]];
+ [self showAtPoint:point inView:view withContentView:[container AUTORELEASE]];
}
- (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withViewArray:(NSArray *)viewArray
@@ -340,13 +340,13 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t
self.titleView = titleLabel;
}
- [container addSubview:[titleLabel autorelease]];
+ [container addSubview:[titleLabel AUTORELEASE]];
container.frame = CGRectMake(0, 0, totalWidth, totalHeight);
self.subviewsArray = viewArray;
- [self showAtPoint:point inView:view withContentView:[container autorelease]];
+ [self showAtPoint:point inView:view withContentView:[container AUTORELEASE]];
}
- (void)showAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray
@@ -368,10 +368,10 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArra
[textButton setTitleColor:kTextHighlightColor forState:UIControlStateHighlighted];
[textButton addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
- [labelArray addObject:[textButton autorelease]];
+ [labelArray addObject:[textButton AUTORELEASE]];
}
- [self showAtPoint:point inView:view withViewArray:[labelArray autorelease]];
+ [self showAtPoint:point inView:view withViewArray:[labelArray AUTORELEASE]];
}
- (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withStringArray:(NSArray *)stringArray
@@ -393,10 +393,10 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)t
[textButton setTitleColor:kTextHighlightColor forState:UIControlStateHighlighted];
[textButton addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
- [labelArray addObject:[textButton autorelease]];
+ [labelArray addObject:[textButton AUTORELEASE]];
}
- [self showAtPoint:point inView:view withTitle:title withViewArray:[labelArray autorelease]];
+ [self showAtPoint:point inView:view withTitle:title withViewArray:[labelArray AUTORELEASE]];
}
- (void)showAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray withImageArray:(NSArray *)imageArray
@@ -456,14 +456,14 @@ - (NSMutableArray*) makeTempViewsWithStrings:(NSArray *)stringArray andImages:(N
[containerView addSubview:imageView];
[containerView addSubview:label];
- [label release];
- [imageView release];
+ [label RELEASE];
+ [imageView RELEASE];
[tempViewArray addObject:containerView];
- [containerView release];
+ [containerView RELEASE];
}
- return [tempViewArray autorelease];
+ return [tempViewArray AUTORELEASE];
}
- (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withContentView:(UIView *)cView
@@ -491,7 +491,7 @@ - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withContentView:(UIView
// animate into full size
// First stage animates to 1.05x normal size, then second stage animates back down to 1x size.
// This two-stage animation creates a little "pop" on open.
- [UIView animateWithDuration:0.2f delay:0.f options:UIViewAnimationCurveEaseInOut animations:^{
+ [UIView animateWithDuration:0.2f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.alpha = 1.f;
self.transform = CGAffineTransformMakeScale(1.05f, 1.05f);
} completion:^(BOOL finished) {
@@ -509,7 +509,7 @@ - (void)layoutAtPoint:(CGPoint)point inView:(UIView *)view
[self setupLayout:point inView:view];
// animate back to full opacity
- [UIView animateWithDuration:0.2f delay:0.f options:UIViewAnimationCurveEaseInOut animations:^{
+ [UIView animateWithDuration:0.2f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.alpha = 1.f;
} completion:nil];
}
@@ -593,7 +593,7 @@ -(void)setupLayout:(CGPoint)point inView:(UIView*)view
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
tap.cancelsTouchesInView = NO; // Allow touches through to a UITableView or other touchable view, as suggested by Dimajp.
[self addGestureRecognizer:tap];
- [tap release];
+ [tap RELEASE];
self.userInteractionEnabled = YES;
}
@@ -622,7 +622,7 @@ - (void)showActivityIndicatorWithMessage:(NSString *)msg
}
if (activityIndicator) {
- [activityIndicator release];
+ [activityIndicator RELEASE];
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}
@@ -644,7 +644,7 @@ - (void)hideActivityIndicatorWithMessage:(NSString *)msg
[UIView animateWithDuration:0.1f animations:^{
activityIndicator.alpha = 0.f;
} completion:^(BOOL finished) {
- [activityIndicator release];
+ [activityIndicator RELEASE];
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}];
@@ -657,7 +657,7 @@ - (void)showImage:(UIImage *)image withMessage:(NSString *)msg
imageView.frame = CGRectMake(floorf(CGRectGetMidX(contentView.bounds) - image.size.width*0.5f), floorf(CGRectGetMidY(contentView.bounds) - image.size.height*0.5f + ((self.titleView) ? 20 : 0.f)), image.size.width, image.size.height);
imageView.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
- [contentView addSubview:[imageView autorelease]];
+ [contentView addSubview:[imageView AUTORELEASE]];
if (subviewsArray && (subviewsArray.count > 0)) {
[UIView animateWithDuration:0.2f animations:^{
@@ -678,7 +678,7 @@ - (void)showImage:(UIImage *)image withMessage:(NSString *)msg
}
}
- [UIView animateWithDuration:0.2f delay:0.2f options:UIViewAnimationCurveEaseOut animations:^{
+ [UIView animateWithDuration:0.2f delay:0.2f options:UIViewAnimationOptionCurveEaseOut animations:^{
imageView.alpha = 1.f;
imageView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
@@ -693,7 +693,7 @@ - (void)showError
imageView.frame = CGRectMake(CGRectGetMidX(contentView.bounds) - 20.f, CGRectGetMidY(contentView.bounds) - 20.f + ((self.titleView) ? 20 : 0.f), 40.f, 40.f);
imageView.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
- [contentView addSubview:[imageView autorelease]];
+ [contentView addSubview:[imageView AUTORELEASE]];
if (subviewsArray && (subviewsArray.count > 0)) {
[UIView animateWithDuration:0.1f animations:^{
@@ -708,7 +708,7 @@ - (void)showError
}
}
- [UIView animateWithDuration:0.1f delay:0.1f options:UIViewAnimationCurveEaseOut animations:^{
+ [UIView animateWithDuration:0.1f delay:0.1f options:UIViewAnimationOptionCurveEaseOut animations:^{
imageView.alpha = 1.f;
imageView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
@@ -724,7 +724,7 @@ - (void)showSuccess
imageView.frame = CGRectMake(CGRectGetMidX(contentView.bounds) - 20.f, CGRectGetMidY(contentView.bounds) - 20.f + ((self.titleView) ? 20 : 0.f), 40.f, 40.f);
imageView.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
- [contentView addSubview:[imageView autorelease]];
+ [contentView addSubview:[imageView AUTORELEASE]];
if (subviewsArray && (subviewsArray.count > 0)) {
[UIView animateWithDuration:0.1f animations:^{
@@ -739,7 +739,7 @@ - (void)showSuccess
}
}
- [UIView animateWithDuration:0.1f delay:0.1f options:UIViewAnimationCurveEaseOut animations:^{
+ [UIView animateWithDuration:0.1f delay:0.1f options:UIViewAnimationOptionCurveEaseOut animations:^{
imageView.alpha = 1.f;
imageView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
@@ -927,7 +927,7 @@ - (void)drawRect:(CGRect)rect
(id)kGradientTopColor.CGColor,
(id)kGradientBottomColor.CGColor, nil];
CGFloat gradientLocations[] = {0, 1};
- CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)gradientColors, gradientLocations);
+ CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFTYPECAST(CFArrayRef)gradientColors), gradientLocations);
//These floats are the top and bottom offsets for the gradient drawing so the drawing includes the arrows.
@@ -993,7 +993,7 @@ - (void)drawRect:(CGRect)rect
(id)kGradientTitleTopColor.CGColor,
(id)kGradientTitleBottomColor.CGColor, nil];
CGFloat gradientLocations[] = {0, 1};
- CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)gradientColors, gradientLocations);
+ CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFTYPECAST(CFArrayRef)gradientColors), gradientLocations);
//These floats are the top and bottom offsets for the gradient drawing so the drawing includes the arrows.

0 comments on commit 2aa7aea

Please sign in to comment.