Skip to content

Commit

Permalink
BUGFIX: correct low memory handling
Browse files Browse the repository at this point in the history
  • Loading branch information
weissi committed May 14, 2012
1 parent 23c9a6b commit 77be6da
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 72 deletions.
4 changes: 4 additions & 0 deletions FRLayeredNavigationController.xcodeproj/project.pbxproj
Expand Up @@ -407,6 +407,7 @@
GCC_PREFIX_HEADER = "FRLayeredNavigationController/FRLayeredNavigationController-Prefix.pch";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
SKIP_INSTALL = YES;
};
name = Debug;
Expand All @@ -419,6 +420,7 @@
GCC_PREFIX_HEADER = "FRLayeredNavigationController/FRLayeredNavigationController-Prefix.pch";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
SKIP_INSTALL = YES;
};
name = Release;
Expand All @@ -435,6 +437,7 @@
"-all_load",
);
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
TARGETED_DEVICE_FAMILY = 2;
WRAPPER_EXTENSION = app;
};
Expand All @@ -453,6 +456,7 @@
"-all_load",
);
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
TARGETED_DEVICE_FAMILY = 2;
WRAPPER_EXTENSION = app;
};
Expand Down
105 changes: 43 additions & 62 deletions FRLayeredNavigationController/FRLayerController.m
Expand Up @@ -34,44 +34,34 @@ @interface FRLayerController ()

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

@end

@implementation FRLayerController

#pragma mark - init/dealloc

- (id)initWithContentViewController:(UIViewController *)vc maximumWidth:(BOOL)maxWidth {
if ((self = [super init])) {
_layeredNavigationItem = [[FRLayeredNavigationItem alloc] init];
_layeredNavigationItem.layerController = self;
_contentViewController = vc;
_maximumWidth = maxWidth;

[self attachContentViewController];
}
assert(self.parentViewController == nil);

return self;
}

- (void)dealloc
{
self.layeredNavigationItem.layerController = nil;
[self detachContentViewController];
}

- (void)loadView {
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor clearColor];
}
#pragma mark - internal methods

- (void)willMoveToParentViewController:(UIViewController *)parent {
if (parent == nil) {
/* will be REMOVED from a container controller */
[self.contentViewController willMoveToParentViewController:nil];
[self.contentViewController removeFromParentViewController];
} else {
/* will be added to a container controller */
[self addChildViewController:self.contentViewController];
}
}

- (void)doViewLayout {
CGRect contentFrame = CGRectZero;
Expand Down Expand Up @@ -99,67 +89,59 @@ - (void)doViewLayout {
}


self.contentView.frame = contentFrame;
self.contentViewController.view.frame = contentFrame;
}

- (void)viewWillLayoutSubviews {
self.view.layer.shadowRadius = 10.0;
self.view.layer.shadowOffset = CGSizeMake(-2.0, -3.0);
self.view.layer.shadowOpacity = 0.5;
self.view.layer.shadowColor = [UIColor blackColor].CGColor;
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
- (void)attachContentViewController
{
[self addChildViewController:self.contentViewController];
[self.contentViewController didMoveToParentViewController:self];
}

[self doViewLayout];
- (void)detachContentViewController
{
[self.contentViewController willMoveToParentViewController:nil];
[self.contentViewController removeFromParentViewController];
}

- (void)didMoveToParentViewController:(UIViewController *)parent {
if (parent != nil) {
assert(self.parentViewController == parent);

const FRLayeredNavigationItem *navItem = self.layeredNavigationItem;

self.contentView = self.contentViewController.view;

if (self.layeredNavigationItem.hasChrome) {
self.chromeView = [[FRLayerChromeView alloc] initWithFrame:CGRectZero
titleView:navItem.titleView
title:navItem.title == nil ?
self.contentViewController.title : navItem.title];

self.borderView = [[UIView alloc] init];
self.borderView.backgroundColor = [UIColor colorWithWhite:236.0f/255.0f alpha:1];

[self.view addSubview:self.chromeView];
[self.view addSubview:self.borderView];
}
[self.view addSubview:self.contentView];

[self doViewLayout];

[self.contentViewController didMoveToParentViewController:self];
} else {
[self.contentView removeFromSuperview];
[self.chromeView removeFromSuperview];
[self.borderView removeFromSuperview];
#pragma mark - UIViewController interface methods

- (void)loadView {
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor clearColor];

const FRLayeredNavigationItem *navItem = self.layeredNavigationItem;

if (self.layeredNavigationItem.hasChrome) {
self.chromeView = [[FRLayerChromeView alloc] initWithFrame:CGRectZero
titleView:navItem.titleView
title:navItem.title == nil ?
self.contentViewController.title : navItem.title];

self.contentView = nil;
self.borderView = nil;
self.chromeView = nil;
self.borderView = [[UIView alloc] init];
self.borderView.backgroundColor = [UIColor colorWithWhite:236.0f/255.0f alpha:1];

self.contentViewController = nil;
[self.view addSubview:self.chromeView];
[self.view addSubview:self.borderView];
}
[self.view addSubview:self.contentViewController.view];
}

- (void)viewDidLoad
{
[super viewDidLoad];
- (void)viewWillLayoutSubviews {
self.view.layer.shadowRadius = 10.0;
self.view.layer.shadowOffset = CGSizeMake(-2.0, -3.0);
self.view.layer.shadowOpacity = 0.5;
self.view.layer.shadowColor = [UIColor blackColor].CGColor;
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;

[self doViewLayout];
}

- (void)viewDidUnload
{
[super viewDidUnload];
NSLog(@"FRLayerController (%@): viewDidUnload", self);

self.contentView = nil;
self.borderView = nil;
self.chromeView = nil;
}
Expand All @@ -172,7 +154,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
@synthesize contentViewController = _contentViewController;
@synthesize maximumWidth = _maximumWidth;
@synthesize borderView = _borderView;
@synthesize contentView = _contentView;
@synthesize chromeView = _chromeView;
@synthesize layeredNavigationItem = _layeredNavigationItem;

Expand Down
28 changes: 18 additions & 10 deletions FRLayeredNavigationController/FRLayeredNavigationController.m
Expand Up @@ -46,6 +46,7 @@ @interface FRLayeredNavigationController ()
@implementation FRLayeredNavigationController

#pragma mark - Initialization/dealloc

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
return [self initWithRootViewController:rootViewController configuration:^(FRLayeredNavigationItem *item) {
Expand All @@ -65,6 +66,9 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController
layeredRC.layeredNavigationItem.hasChrome = NO;
configuration(layeredRC.layeredNavigationItem);
_outOfBoundsViewController = nil;

[self addChildViewController:layeredRC];
[layeredRC didMoveToParentViewController:self];
}
return self;
}
Expand All @@ -78,16 +82,16 @@ - (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];
[self addChildViewController:rootViewController];

self.view = [[UIView alloc] init];
CGRect rootViewFrame = CGRectMake(0, 0, rootViewController.layeredNavigationItem.width, self.view.bounds.size.height);
rootViewController.view.frame = rootViewFrame;
rootViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self.view addSubview:rootViewController.view];
[rootViewController didMoveToParentViewController:self];

for (FRLayerController *vc in self.viewControllers) {
vc.view.frame = CGRectMake(vc.layeredNavigationItem.currentViewPosition.x,
vc.layeredNavigationItem.currentViewPosition.y,
vc.layeredNavigationItem.width,
self.view.frame.size.height);
vc.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self.view addSubview:vc.view];
}
}

- (void)viewDidLoad
Expand All @@ -98,6 +102,7 @@ - (void)viewDidLoad
self.panGR.maximumNumberOfTouches = 1;
self.panGR.delegate = self;
[self.view addGestureRecognizer:self.panGR];
self.view.backgroundColor = [UIColor clearColor];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)orientation
Expand All @@ -121,12 +126,15 @@ - (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...");
self.panGR = nil;
self.firstTouchedView = nil;
self.outOfBoundsViewController = nil;
}

- (void)viewDidUnload
{
[super viewDidUnload];
NSLog(@"FRLayeredNavigationController (%@): viewDidUnload", self);
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Expand Down

0 comments on commit 77be6da

Please sign in to comment.