diff --git a/SWRevealViewController/SWRevealViewController.m b/SWRevealViewController/SWRevealViewController.m index 81c7df6..a657cc3 100755 --- a/SWRevealViewController/SWRevealViewController.m +++ b/SWRevealViewController/SWRevealViewController.m @@ -154,6 +154,20 @@ - (void)prepareRightViewForPosition:(FrontViewPosition)newPosition } +- (void)unloadRearView +{ + [_rearView removeFromSuperview]; + _rearView = nil; +} + + +- (void)unloadRightView +{ + [_rightView removeFromSuperview]; + _rightView = nil; +} + + - (CGFloat)frontLocationForPosition:(FrontViewPosition)frontViewPosition { CGFloat revealWidth; @@ -1540,7 +1554,17 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV _rearViewPosition = newPosition; - return [self _deploymentForViewController:_rearViewController inView:_contentView.rearView appear:appear disappear:disappear]; + void (^deploymentCompletion)() = + [self _deploymentForViewController:_rearViewController inView:_contentView.rearView appear:appear disappear:disappear]; + + void (^completion)() = ^() + { + deploymentCompletion(); + if ( disappear ) + [_contentView unloadRearView]; + }; + + return completion; } // Deploy/Undeploy of the right view controller following the containment principles. Returns a block @@ -1558,7 +1582,17 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV _rightViewPosition = newPosition; - return [self _deploymentForViewController:_rightViewController inView:_contentView.rightView appear:appear disappear:disappear]; + void (^deploymentCompletion)() = + [self _deploymentForViewController:_rightViewController inView:_contentView.rightView appear:appear disappear:disappear]; + + void (^completion)() = ^() + { + deploymentCompletion(); + if ( disappear ) + [_contentView unloadRightView]; + }; + + return completion; }