Skip to content

Commit

Permalink
MINOR: more correct ARC use
Browse files Browse the repository at this point in the history
  • Loading branch information
weissi committed May 12, 2012
1 parent 9da6751 commit 3f7369a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 71 deletions.
2 changes: 1 addition & 1 deletion FRLayeredNavigationController/FRLayerChromeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ -(id)initWithFrame:(CGRect)frame titleView:(UIView *)titleView title:(NSString *
{
self = [super initWithFrame:frame];
if (self) {
self->_savedGradient = nil;
_savedGradient = nil;
self.backgroundColor = [UIColor clearColor];

if (titleView == nil) {
Expand Down
21 changes: 11 additions & 10 deletions FRLayeredNavigationController/FRLayerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@
#import "FRLayeredNavigationItem.h"

@interface FRLayerController : UIViewController {
UIViewController *contentViewController;
FRLayeredNavigationItem *layeredNavigationItem;
@private
FRLayeredNavigationItem *_layeredNavigationItem;

BOOL leaf;
BOOL _maximumWidth;

FRLayerChromeView *chromeView;
UIView *borderView;
UIView *contentView;
FRLayerChromeView *_chromeView;
UIView *_borderView;

UIViewController *_contentViewController;
}

- (id)initWithContentViewController:(UIViewController *)contentViewController leaf:(BOOL)isLeaf;
- (id)initWithContentViewController:(UIViewController *)contentViewController maximumWidth:(BOOL)maxWidth;

@property (nonatomic, readonly, retain) FRLayeredNavigationItem *layeredNavigationItem;
@property (nonatomic, readonly, retain) UIViewController *contentViewController;
@property (nonatomic, readonly, assign) BOOL leaf;
@property (nonatomic, readonly, strong) FRLayeredNavigationItem *layeredNavigationItem;
@property (nonatomic, readonly, strong) UIViewController *contentViewController;
@property (nonatomic, readonly) BOOL maximumWidth;

@end
32 changes: 16 additions & 16 deletions FRLayeredNavigationController/FRLayerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@

@interface FRLayerController ()

@property (nonatomic, readwrite, retain) UIViewController *contentViewController;
@property (nonatomic, readwrite, retain) FRLayeredNavigationItem *layeredNavigationItem;
@property (nonatomic, readwrite, assign) BOOL leaf;
@property (nonatomic, readwrite, strong) UIViewController *contentViewController;
@property (nonatomic, readwrite, strong) FRLayeredNavigationItem *layeredNavigationItem;
@property (nonatomic, readwrite) BOOL maximumWidth;

@property (nonatomic, retain) FRLayerChromeView *chromeView;
@property (nonatomic, retain) UIView *borderView;
@property (nonatomic, retain) UIView *contentView;
@property (nonatomic, strong) FRLayerChromeView *chromeView;
@property (nonatomic, strong) UIView *borderView;
@property (nonatomic, strong) UIView *contentView;

@end

@implementation FRLayerController

- (id)initWithContentViewController:(UIViewController *)aContentViewController leaf:(BOOL)isLeaf {
- (id)initWithContentViewController:(UIViewController *)vc maximumWidth:(BOOL)maxWidth {
if ((self = [super init])) {
self.contentViewController = aContentViewController;
self.layeredNavigationItem = [[FRLayeredNavigationItem alloc] init];
self.leaf = isLeaf;
_layeredNavigationItem = [[FRLayeredNavigationItem alloc] init];
_contentViewController = vc;
_maximumWidth = maxWidth;
}
assert(self.parentViewController == nil);

Expand Down Expand Up @@ -160,11 +160,11 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return YES;
}

@synthesize contentViewController;
@synthesize leaf;
@synthesize borderView;
@synthesize contentView;
@synthesize chromeView;
@synthesize layeredNavigationItem;
@synthesize contentViewController = _contentViewController;
@synthesize maximumWidth = _maximumWidth;
@synthesize borderView = _borderView;
@synthesize contentView = _contentView;
@synthesize chromeView = _chromeView;
@synthesize layeredNavigationItem = _layeredNavigationItem;

@end
10 changes: 4 additions & 6 deletions FRLayeredNavigationController/FRLayeredNavigationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
#import "Utils.h"

@interface FRLayeredNavigationController : UIViewController<UIGestureRecognizerDelegate> {
UIView *firstTouchedView;
NSMutableArray *viewControllers;
UIPanGestureRecognizer *panGR;
@private
UIView *_firstTouchedView;
NSMutableArray *_viewControllers;
UIPanGestureRecognizer *_panGR;
}

- (id)initWithRootViewController:(UIViewController *)rootViewController;
Expand All @@ -50,7 +51,4 @@
animated:(BOOL)animated
configuration:(void (^)(FRLayeredNavigationItem *item))configuration;


@property (nonatomic, readonly, retain) NSArray *viewControllers;

@end
55 changes: 28 additions & 27 deletions FRLayeredNavigationController/FRLayeredNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

@interface FRLayeredNavigationController ()

@property (nonatomic, readwrite, retain) UIPanGestureRecognizer *panGR;
@property (nonatomic, readwrite, retain) UIView *firstTouchedView;
@property (nonatomic, readwrite, strong) UIPanGestureRecognizer *panGR;
@property (nonatomic, readwrite, strong) UIView *firstTouchedView;
@property (nonatomic, readwrite, strong) NSMutableArray *viewControllers;

@end

Expand All @@ -48,8 +49,8 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super init];
if (self) {
FRLayerController *layeredRC = [[FRLayerController alloc] initWithContentViewController:rootViewController leaf:NO];
self->viewControllers = [[NSMutableArray alloc] initWithObjects:layeredRC, nil];
FRLayerController *layeredRC = [[FRLayerController alloc] initWithContentViewController:rootViewController maximumWidth:NO];
_viewControllers = [[NSMutableArray alloc] initWithObjects:layeredRC, nil];
layeredRC.layeredNavigationItem.nextItemDistance = kFRLayeredNavigationControllerStandardDistance;
layeredRC.layeredNavigationItem.width = kFRLayeredNavigationControllerStandardWidth;
layeredRC.layeredNavigationItem.hasChrome = NO;
Expand All @@ -67,8 +68,8 @@ - (void)dealloc {

- (void)loadView
{
NSAssert([self->viewControllers count] == 1, @"This is a bug, more than one ViewController present! Go on and implement more sophisticated view loading/unloading...");
UIViewController *rootViewController = [self->viewControllers objectAtIndex:0];
NSAssert([self.viewControllers count] == 1, @"This is a bug, more than one ViewController present! Go on and implement more sophisticated view loading/unloading...");
UIViewController *rootViewController = [self.viewControllers objectAtIndex:0];
[self addChildViewController:rootViewController];

self.view = [[UIView alloc] init];
Expand All @@ -92,11 +93,11 @@ - (void)viewDidLoad
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)orientation
{
NSLog(@"ORIENTATION");
for (FRLayerController *vc in self->viewControllers) {
for (FRLayerController *vc in self.viewControllers) {
CGRect f = vc.view.frame;
f.origin = vc.layeredNavigationItem.currentViewPosition;

if (vc.leaf) {
if (vc.maximumWidth) {
f.size.width = self.view.bounds.size.width - vc.layeredNavigationItem.initialViewPosition.x;
vc.layeredNavigationItem.width = f.size.width;
}
Expand All @@ -110,7 +111,7 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)orientation

- (void)viewWillUnload
{
NSAssert([self->viewControllers count] == 1, @"This is a bug, more than one ViewController present! Go on and implement more sophisticated view loading/unloading...");
NSAssert([self.viewControllers count] == 1, @"This is a bug, more than one ViewController present! Go on and implement more sophisticated view loading/unloading...");
}

- (void)viewDidUnload
Expand Down Expand Up @@ -145,8 +146,8 @@ - (void)handleGesture:(UIPanGestureRecognizer *)gestureRecognizer
case UIGestureRecognizerStateChanged: {
//NSLog(@"UIGestureRecognizerStateChanged, vel=%f", [gestureRecognizer velocityInView:firstView].x);

const NSInteger startVcIdx = [self->viewControllers count]-1;
const UIViewController *startVc = [self->viewControllers objectAtIndex:startVcIdx];
const NSInteger startVcIdx = [self.viewControllers count]-1;
const UIViewController *startVc = [self.viewControllers objectAtIndex:startVcIdx];

[self moveViewControllerIndex:startVcIdx
withGestureRecognizer:gestureRecognizer
Expand Down Expand Up @@ -224,7 +225,7 @@ - (void)viewControllersToSnappingPointsExpand:(BOOL)expand {
FRLayerController *last = nil;
CGFloat xTranslation = 0;

for (FRLayerController *vc in self->viewControllers) {
for (FRLayerController *vc in self.viewControllers) {
const CGPoint myPos = vc.layeredNavigationItem.currentViewPosition;
const CGPoint myInitPos = vc.layeredNavigationItem.initialViewPosition;

Expand Down Expand Up @@ -321,7 +322,7 @@ - (CGFloat)savePlaceWanted:(CGFloat)pointsWanted;
return 0;
}

for (FRLayerController *vc in self->viewControllers) {
for (FRLayerController *vc in self.viewControllers) {
const CGFloat initX = vc.layeredNavigationItem.initialViewPosition.x;
const CGFloat currentX = vc.layeredNavigationItem.currentViewPosition.x;

Expand All @@ -334,8 +335,8 @@ - (CGFloat)savePlaceWanted:(CGFloat)pointsWanted;
}
}

for (FRLayerController *vc in self->viewControllers) {
if (vc == [self->viewControllers lastObject]) {
for (FRLayerController *vc in self.viewControllers) {
if (vc == [self.viewControllers lastObject]) {
break;
}
[FRLayeredNavigationController viewController:vc xTranslation:xTranslation bounded:YES];
Expand All @@ -348,15 +349,15 @@ - (CGFloat)savePlaceWanted:(CGFloat)pointsWanted;

- (void)popViewControllerAnimated:(BOOL)animated
{
UIViewController *vc = [self->viewControllers lastObject];
UIViewController *vc = [self.viewControllers lastObject];

if ([self->viewControllers count] == 1) {
if ([self.viewControllers count] == 1) {
/* don't remove root view controller */
return;
}

[vc willMoveToParentViewController:nil];
[self->viewControllers removeObject:vc];
[self.viewControllers removeObject:vc];

CGRect goAwayFrame = CGRectMake(vc.view.frame.origin.x, 1024, vc.view.frame.size.width, vc.view.frame.size.height);
[UIView animateWithDuration:animated ? 0.5 : 0
Expand All @@ -375,15 +376,15 @@ - (void)popToViewController:(UIViewController *)vc animated:(BOOL)animated
{
UIViewController *currentVc;

while ((currentVc = [self->viewControllers lastObject])) {
while ((currentVc = [self.viewControllers lastObject])) {
if (([currentVc class] == [FRLayerController class] &&
((FRLayerController*)currentVc).contentViewController == vc) ||
([currentVc class] != [FRLayerController class] &&
currentVc == vc)) {
break;
}

if ([self->viewControllers count] == 1) {
if ([self.viewControllers count] == 1) {
/* don't remove root view controller */
return;
}
Expand All @@ -394,7 +395,7 @@ - (void)popToViewController:(UIViewController *)vc animated:(BOOL)animated

- (void)popToRootViewControllerAnimated:(BOOL)animated
{
[self popToViewController:[self->viewControllers objectAtIndex:0] animated:animated];
[self popToViewController:[self.viewControllers objectAtIndex:0] animated:animated];
}

- (void)pushViewController:(UIViewController *)contentViewController
Expand All @@ -404,7 +405,7 @@ - (void)pushViewController:(UIViewController *)contentViewController
configuration:(void (^)(FRLayeredNavigationItem *item))configuration
{
FRLayerController *newVC = [[FRLayerController alloc]
initWithContentViewController:contentViewController leaf:maxWidth];
initWithContentViewController:contentViewController maximumWidth:maxWidth];
const FRLayeredNavigationItem *navItem = newVC.layeredNavigationItem;
const FRLayeredNavigationItem *parentNavItem = anchorViewController.layeredNavigationItem;

Expand All @@ -428,7 +429,7 @@ - (void)pushViewController:(UIViewController *)contentViewController
if (navItem.width > 0) {
width = navItem.width;
} else {
width = newVC.leaf ? self.view.bounds.size.width - initX : kFRLayeredNavigationControllerStandardWidth;
width = newVC.maximumWidth ? self.view.bounds.size.width - initX : kFRLayeredNavigationControllerStandardWidth;
}

CGRect newFrame = CGRectMake(newVC.layeredNavigationItem.currentViewPosition.x,
Expand All @@ -441,7 +442,7 @@ - (void)pushViewController:(UIViewController *)contentViewController
newFrame.size.height);


[self->viewControllers addObject:newVC];
[self.viewControllers addObject:newVC];
[self addChildViewController:newVC];

[self.view addSubview:newVC.view];
Expand Down Expand Up @@ -480,8 +481,8 @@ - (void)pushViewController:(UIViewController *)contentViewController

#pragma mark - properties

@synthesize viewControllers;
@synthesize panGR;
@synthesize firstTouchedView;
@synthesize viewControllers = _viewControllers;
@synthesize panGR = _panGR;
@synthesize firstTouchedView = _firstTouchedView;

@end
15 changes: 8 additions & 7 deletions FRLayeredNavigationController/FRLayeredNavigationItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import <UIKit/UIKit.h>

@interface FRLayeredNavigationItem : NSObject {
@private
CGPoint initialViewPosition;
CGPoint currentViewPosition;
NSString *title;
Expand All @@ -31,12 +32,12 @@
BOOL hasChrome;
}

@property (nonatomic, readwrite, assign) CGPoint initialViewPosition;
@property (nonatomic, readwrite, assign) CGPoint currentViewPosition;
@property (nonatomic, readwrite, retain) NSString *title;
@property (nonatomic, readwrite, retain) UIView *titleView;
@property (nonatomic, readwrite, assign) CGFloat width;
@property (nonatomic, readwrite, assign) CGFloat nextItemDistance;
@property (nonatomic, readwrite, assign) BOOL hasChrome;
@property (nonatomic, readwrite) CGPoint initialViewPosition;
@property (nonatomic, readwrite) CGPoint currentViewPosition;
@property (nonatomic, readwrite, strong) NSString *title;
@property (nonatomic, readwrite, strong) UIView *titleView;
@property (nonatomic, readwrite) CGFloat width;
@property (nonatomic, readwrite) CGFloat nextItemDistance;
@property (nonatomic, readwrite) BOOL hasChrome;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@interface UIViewController (FRLayeredNavigationController)

@property (nonatomic, readonly, retain) FRLayeredNavigationController *layeredNavigationController;
@property (nonatomic, readonly, retain) FRLayeredNavigationItem *layeredNavigationItem;
@property (nonatomic, readonly, strong) FRLayeredNavigationController *layeredNavigationController;
@property (nonatomic, readonly, strong) FRLayeredNavigationItem *layeredNavigationItem;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

@interface SampleContentViewController ()

@property (nonatomic, readwrite, retain) UIImageView *imageView;
@property (nonatomic, readwrite, retain) UIScrollView *scrollView;
@property (nonatomic, readwrite, strong) UIImageView *imageView;
@property (nonatomic, readwrite, strong) UIScrollView *scrollView;

@end

Expand Down

0 comments on commit 3f7369a

Please sign in to comment.