diff --git a/RevealControllerExample/RevealControllerProject.xcodeproj/project.pbxproj b/RevealControllerExample/RevealControllerProject.xcodeproj/project.pbxproj index c00cd79..25313cf 100755 --- a/RevealControllerExample/RevealControllerProject.xcodeproj/project.pbxproj +++ b/RevealControllerExample/RevealControllerProject.xcodeproj/project.pbxproj @@ -48,10 +48,10 @@ 4EE05DEE16BE643D0046E135 /* RightViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RightViewController.h; sourceTree = ""; }; 4EE05DEF16BE643D0046E135 /* RightViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RightViewController.m; sourceTree = ""; }; 4EE05DF016BE643D0046E135 /* RightViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RightViewController.xib; sourceTree = ""; }; - 5E1EFE0F14A0BA4F008062C1 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/FrontViewController.xib; sourceTree = ""; }; - 5E1EFE1314A0BA4F008062C1 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/RearViewController.xib; sourceTree = ""; }; + 55F63667224E0E6000F347B3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/RearViewController.xib; sourceTree = ""; }; + 55F63668224E0E6000F347B3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/FrontViewController.xib; sourceTree = ""; }; + 55F63669224E0E6000F347B3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MapViewController.xib; sourceTree = ""; }; 5E5A2CFF14E0CD8D0042AE1E /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; - 5E5A2D0714E0D1600042AE1E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MapViewController.xib; sourceTree = ""; }; 5E605BA514A081F900853025 /* RevealControllerProject.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RevealControllerProject.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5E605BA914A081F900853025 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 5E605BAB14A081F900853025 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -236,14 +236,15 @@ 5E605B9C14A081F900853025 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0630; + LastUpgradeCheck = 1020; }; buildConfigurationList = 5E605B9F14A081F900853025 /* Build configuration list for PBXProject "RevealControllerProject" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 5E605B9A14A081F900853025; productRefGroup = 5E605BA614A081F900853025 /* Products */; @@ -295,7 +296,7 @@ 5E1EFE0E14A0BA4F008062C1 /* FrontViewController.xib */ = { isa = PBXVariantGroup; children = ( - 5E1EFE0F14A0BA4F008062C1 /* en */, + 55F63668224E0E6000F347B3 /* Base */, ); name = FrontViewController.xib; sourceTree = ""; @@ -303,7 +304,7 @@ 5E1EFE1214A0BA4F008062C1 /* RearViewController.xib */ = { isa = PBXVariantGroup; children = ( - 5E1EFE1314A0BA4F008062C1 /* en */, + 55F63667224E0E6000F347B3 /* Base */, ); name = RearViewController.xib; sourceTree = ""; @@ -311,7 +312,7 @@ 5E5A2D0614E0D1600042AE1E /* MapViewController.xib */ = { isa = PBXVariantGroup; children = ( - 5E5A2D0714E0D1600042AE1E /* en */, + 55F63669224E0E6000F347B3 /* Base */, ); name = MapViewController.xib; sourceTree = ""; @@ -331,17 +332,29 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -371,12 +384,23 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = ""; @@ -407,6 +431,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "RevealControllerProject/Project-Prefix.pch"; INFOPLIST_FILE = "RevealControllerProject/RevealControllerProject-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "org.zuui.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -418,6 +443,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "RevealControllerProject/Project-Prefix.pch"; INFOPLIST_FILE = "RevealControllerProject/RevealControllerProject-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "org.zuui.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/RevealControllerExample/RevealControllerProject.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/RevealControllerExample/RevealControllerProject.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/RevealControllerExample/RevealControllerProject.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/RevealControllerExample/RevealControllerProject/en.lproj/FrontViewController.xib b/RevealControllerExample/RevealControllerProject/Base.lproj/FrontViewController.xib similarity index 100% rename from RevealControllerExample/RevealControllerProject/en.lproj/FrontViewController.xib rename to RevealControllerExample/RevealControllerProject/Base.lproj/FrontViewController.xib diff --git a/RevealControllerExample/RevealControllerProject/en.lproj/MapViewController.xib b/RevealControllerExample/RevealControllerProject/Base.lproj/MapViewController.xib similarity index 100% rename from RevealControllerExample/RevealControllerProject/en.lproj/MapViewController.xib rename to RevealControllerExample/RevealControllerProject/Base.lproj/MapViewController.xib diff --git a/RevealControllerExample/RevealControllerProject/en.lproj/RearViewController.xib b/RevealControllerExample/RevealControllerProject/Base.lproj/RearViewController.xib similarity index 100% rename from RevealControllerExample/RevealControllerProject/en.lproj/RearViewController.xib rename to RevealControllerExample/RevealControllerProject/Base.lproj/RearViewController.xib diff --git a/RevealControllerExample/RevealControllerProject/RevealControllerProject-Info.plist b/RevealControllerExample/RevealControllerProject/RevealControllerProject-Info.plist index 33727c6..ff11304 100755 --- a/RevealControllerExample/RevealControllerProject/RevealControllerProject-Info.plist +++ b/RevealControllerExample/RevealControllerProject/RevealControllerProject-Info.plist @@ -11,7 +11,7 @@ CFBundleIconFiles CFBundleIdentifier - org.zuui.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SWRevealViewController/SWRevealViewController.h b/SWRevealViewController/SWRevealViewController.h index 345dfaa..de1daf4 100755 --- a/SWRevealViewController/SWRevealViewController.h +++ b/SWRevealViewController/SWRevealViewController.h @@ -1,5 +1,5 @@ /* - + Copyright (c) 2013 Joan Lluch Permission is hereby granted, free of charge, to any person obtaining a copy @@ -19,24 +19,24 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + Early code inspired on a similar class by Philip Kluz (Philip.Kluz@zuui.org) -*/ + */ /* - + RELEASE NOTES Version 2.4.0 (Current Version) - - Updated behaviour of appearance method calls on child controllers - - Removes Xcode 6.3.1 warnings + - Updated behaviour of appearance method calls on child controllers + - Removes Xcode 6.3.1 warnings Version 2.3.0 - - StoryBoard initializing bug fix - - Minor Code refactoring + - StoryBoard initializing bug fix + - Minor Code refactoring Version 2.2.0 @@ -65,57 +65,57 @@ Version 2.0.0 -- Dropped support for iOS6 and earlier. This version will only work on iOS7 + - Dropped support for iOS6 and earlier. This version will only work on iOS7 -- The method setFrontViewController:animated: does not longer perform a full reveal animation. Instead it just replaces the frontViewController in - its current position. Use the new pushFrontViewController:animated: method to perform a replacement of the front controlles with reveal animation - as in the previous version - - IMPORTANT: You must replace all calls to setFrontViewController:animated by calls to pushFrontViewController:animated to prevent breaking - functionality on existing projects. + - The method setFrontViewController:animated: does not longer perform a full reveal animation. Instead it just replaces the frontViewController in + its current position. Use the new pushFrontViewController:animated: method to perform a replacement of the front controlles with reveal animation + as in the previous version -- Added support for animated replacement of child controllers: setRearViewController, setFrontViewController, setRightViewController now have animated versions. + IMPORTANT: You must replace all calls to setFrontViewController:animated by calls to pushFrontViewController:animated to prevent breaking + functionality on existing projects. -- The new 'replaceViewAnimationDuration' property sets the default duration of child viewController replacement. + - Added support for animated replacement of child controllers: setRearViewController, setFrontViewController, setRightViewController now have animated versions. -- Added the following new delegate methods - revealController:willAddViewController:forOperation:animated: - revealController:didAddViewController:forOperation:animated: - -- The class also supports custom UIViewControllerAnimatedTransitioning related with the replacement of child viewControllers. - You can implement the following new delegate method: revealController:animationControllerForOperation:fromViewController:toViewController: - and provide an object conforming to UIViewControllerAnimatedTransitioning to implement custom animations. + - The new 'replaceViewAnimationDuration' property sets the default duration of child viewController replacement. + + - Added the following new delegate methods + revealController:willAddViewController:forOperation:animated: + revealController:didAddViewController:forOperation:animated: + + - The class also supports custom UIViewControllerAnimatedTransitioning related with the replacement of child viewControllers. + You can implement the following new delegate method: revealController:animationControllerForOperation:fromViewController:toViewController: + and provide an object conforming to UIViewControllerAnimatedTransitioning to implement custom animations. Version 1.1.3 -- Reverted the supportedInterfaceOrientations to the default behavior. This is consistent with Apple provided controllers - -- The presentFrontViewHierarchically now dynamically takes into account the smaller header height of bars on iPhone landscape orientation + - Reverted the supportedInterfaceOrientations to the default behavior. This is consistent with Apple provided controllers + + - The presentFrontViewHierarchically now dynamically takes into account the smaller header height of bars on iPhone landscape orientation Version 1.1.2 - - The status bar style and appearance are now handled in sync with the class animations. - You can implement the methods preferredStatusBarStyle and prefersStatusBarHidden on your child controllers to define the desired appearance - + - The status bar style and appearance are now handled in sync with the class animations. + You can implement the methods preferredStatusBarStyle and prefersStatusBarHidden on your child controllers to define the desired appearance + - The loadView method now calls a method, loadStoryboardControllers, just for the purpose of loading child controllers from a storyboard. - You can override this method and remove the @try @catch statements if you want the debugger not to stop at them in case you have set an exception breakpoint. + You can override this method and remove the @try @catch statements if you want the debugger not to stop at them in case you have set an exception breakpoint. Version 1.1.1 - You can now get a tapGestureRecognizer from the class. See the tapGestureRecognizer method for more information. - Both the panGestureRecognizer and the tapGestureRecognizer are now attached to the revealViewController's front content view - by default, so they will start working just by calling their access methods even if you do not attach them to any of your views. - This enables you to dissable interactions on your views -for example based on position- without breaking normal gesture behavior. + by default, so they will start working just by calling their access methods even if you do not attach them to any of your views. + This enables you to dissable interactions on your views -for example based on position- without breaking normal gesture behavior. - Corrected a bug that caused a crash on iOS6 and earlier. Version 1.1.0 - + - The method setFrontViewController:animated now performs the correct animations both for left and right controllers. - + - The class now automatically handles the status bar appearance depending on the currently shown child controller. - + Version 1.0.8 - Support for constant width frontView by setting a negative value to reveal widths. See properties rearViewRevealWidth and rightViewRevealWidth @@ -123,18 +123,18 @@ - Support for draggableBorderWidth. See property of the same name. - The Pan gesture recongnizer can be disabled by implementing the following delegate method and returning NO - revealControllerPanGestureShouldBegin: - + revealControllerPanGestureShouldBegin: + - Added the ability to track pan gesture reveal progress through the following new delegate methods - revealController:panGestureBeganFromLocation:progress: - revealController:panGestureMovedToLocation:progress: - revealController:panGestureEndedToLocation:progress: + revealController:panGestureBeganFromLocation:progress: + revealController:panGestureMovedToLocation:progress: + revealController:panGestureEndedToLocation:progress: Previous Versions - No release notes were updated for previous versions. - -*/ + + */ #import @@ -147,38 +147,38 @@ // Enum values for setFrontViewPosition:animated: typedef NS_ENUM( NSInteger, FrontViewPosition) { - // Front controller is removed from view. Animated transitioning from this state will cause the same - // effect than animating from FrontViewPositionLeftSideMost. Use this instead of FrontViewPositionLeftSideMost when - // you want to remove the front view controller view from the view hierarchy. - FrontViewPositionLeftSideMostRemoved, - - // Left most position, front view is presented left-offseted by rightViewRevealWidth+rigthViewRevealOverdraw - FrontViewPositionLeftSideMost, - - // Left position, front view is presented left-offseted by rightViewRevealWidth - FrontViewPositionLeftSide, - - // Center position, rear view is hidden behind front controller + // Front controller is removed from view. Animated transitioning from this state will cause the same + // effect than animating from FrontViewPositionLeftSideMost. Use this instead of FrontViewPositionLeftSideMost when + // you want to remove the front view controller view from the view hierarchy. + FrontViewPositionLeftSideMostRemoved, + + // Left most position, front view is presented left-offseted by rightViewRevealWidth+rigthViewRevealOverdraw + FrontViewPositionLeftSideMost, + + // Left position, front view is presented left-offseted by rightViewRevealWidth + FrontViewPositionLeftSide, + + // Center position, rear view is hidden behind front controller FrontViewPositionLeft, - - // Right possition, front view is presented right-offseted by rearViewRevealWidth + + // Right possition, front view is presented right-offseted by rearViewRevealWidth FrontViewPositionRight, - - // Right most possition, front view is presented right-offseted by rearViewRevealWidth+rearViewRevealOverdraw + + // Right most possition, front view is presented right-offseted by rearViewRevealWidth+rearViewRevealOverdraw FrontViewPositionRightMost, - - // Front controller is removed from view. Animated transitioning from this state will cause the same - // effect than animating from FrontViewPositionRightMost. Use this instead of FrontViewPositionRightMost when - // you intent to remove the front controller view from the view hierarchy. - FrontViewPositionRightMostRemoved, - + + // Front controller is removed from view. Animated transitioning from this state will cause the same + // effect than animating from FrontViewPositionRightMost. Use this instead of FrontViewPositionRightMost when + // you intent to remove the front controller view from the view hierarchy. + FrontViewPositionRightMostRemoved, + }; // Enum values for toggleAnimationType typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType) { - SWRevealToggleAnimationTypeSpring, // <- produces a spring based animation - SWRevealToggleAnimationTypeEaseOut, // <- produces an ease out curve animation + SWRevealToggleAnimationTypeSpring, // <- produces a spring based animation + SWRevealToggleAnimationTypeEaseOut, // <- produces an ease out curve animation }; @@ -236,7 +236,7 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType) - (UITapGestureRecognizer*)tapGestureRecognizer; /* The following properties are provided for further customization, they are set to default values on initialization, - you do not generally have to set them */ + you do not generally have to set them */ // Defines how much of the rear or right view is shown, default is 260. // Negative values indicate that the reveal width should be computed by substracting the full front view width, @@ -308,7 +308,7 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType) @property (nonatomic) BOOL extendsPointInsideHit; /* The class properly handles all the relevant calls to appearance methods on the contained controllers. - Moreover you can assign a delegate to let the class inform you on positions and animation activity */ + Moreover you can assign a delegate to let the class inform you on positions and animation activity */ // Delegate @property (nonatomic,weak) id delegate; @@ -320,11 +320,11 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType) typedef enum { - SWRevealControllerOperationNone, - SWRevealControllerOperationReplaceRearController, - SWRevealControllerOperationReplaceFrontController, - SWRevealControllerOperationReplaceRightController, - + SWRevealControllerOperationNone, + SWRevealControllerOperationReplaceRearController, + SWRevealControllerOperationReplaceFrontController, + SWRevealControllerOperationReplaceRightController, + } SWRevealControllerOperation; @@ -347,11 +347,11 @@ typedef enum // Implement this to return YES if you want other gesture recognizer to share touch events with the pan gesture - (BOOL)revealController:(SWRevealViewController *)revealController - panGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer; +panGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer; // Implement this to return YES if you want other gesture recognizer to share touch events with the tap gesture - (BOOL)revealController:(SWRevealViewController *)revealController - tapGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer; +tapGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer; // Called when the gestureRecognizer began and ended - (void)revealControllerPanGestureBegan:(SWRevealViewController *)revealController; @@ -369,14 +369,14 @@ typedef enum // Notification of child controller replacement - (void)revealController:(SWRevealViewController *)revealController willAddViewController:(UIViewController *)viewController - forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated; + forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated; - (void)revealController:(SWRevealViewController *)revealController didAddViewController:(UIViewController *)viewController - forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated; + forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated; // Support for custom transition animations while replacing child controllers. If implemented, it will be fired in response // to calls to 'setXXViewController' methods - (id)revealController:(SWRevealViewController *)revealController - animationControllerForOperation:(SWRevealControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC; + animationControllerForOperation:(SWRevealControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC; // DEPRECATED - The following delegate methods will be removed some time in the future - (void)revealController:(SWRevealViewController *)revealController panGestureBeganFromLocation:(CGFloat)location progress:(CGFloat)progress; // (DEPRECATED) diff --git a/SWRevealViewController/SWRevealViewController.m b/SWRevealViewController/SWRevealViewController.m index d378d13..916557b 100755 --- a/SWRevealViewController/SWRevealViewController.m +++ b/SWRevealViewController/SWRevealViewController.m @@ -1,5 +1,5 @@ /* - + Copyright (c) 2013 Joan Lluch Permission is hereby granted, free of charge, to any person obtaining a copy @@ -19,10 +19,10 @@ of this software and associated documentation files (the "Software"), to deal LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + Early code inspired on a similar class by Philip Kluz (Philip.Kluz@zuui.org) -*/ + */ #import @@ -35,15 +35,15 @@ Early code inspired on a similar class by Philip Kluz (Philip.Kluz@zuui.org) // it will return the statusBar height if view fully overlaps the statusBar, otherwise returns 0.0f static CGFloat statusBarAdjustment( UIView* view ) { - CGFloat adjustment = 0.0f; - UIApplication *app = [UIApplication sharedApplication]; - CGRect viewFrame = [view convertRect:view.bounds toView:[app keyWindow]]; - CGRect statusBarFrame = [app statusBarFrame]; - - if ( CGRectIntersectsRect(viewFrame, statusBarFrame) ) - adjustment = fminf(statusBarFrame.size.width, statusBarFrame.size.height); - - return adjustment; + CGFloat adjustment = 0.0f; + UIApplication *app = [UIApplication sharedApplication]; + CGRect viewFrame = [view convertRect:view.bounds toView:[app keyWindow]]; + CGRect statusBarFrame = [app statusBarFrame]; + + if ( CGRectIntersectsRect(viewFrame, statusBarFrame) ) + adjustment = fminf(statusBarFrame.size.width, statusBarFrame.size.height); + + return adjustment; } @@ -51,7 +51,7 @@ static CGFloat statusBarAdjustment( UIView* view ) @interface SWRevealView: UIView { - __weak SWRevealViewController *_c; + __weak SWRevealViewController *_c; } @property (nonatomic, readonly) UIView *rearView; @@ -74,130 +74,130 @@ @implementation SWRevealView static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1, CGFloat max1) { - CGFloat result = min2 + (v1-min1)*((max2-min2)/(max1-min1)); - if ( result != result ) return min2; // nan - if ( result < min2 ) return min2; - if ( result > max2 ) return max2; - return result; + CGFloat result = min2 + (v1-min1)*((max2-min2)/(max1-min1)); + if ( result != result ) return min2; // nan + if ( result < min2 ) return min2; + if ( result > max2 ) return max2; + return result; } - (id)initWithFrame:(CGRect)frame controller:(SWRevealViewController*)controller { - self = [super initWithFrame:frame]; - if ( self ) - { - _c = controller; - CGRect bounds = self.bounds; - - _frontView = [[UIView alloc] initWithFrame:bounds]; - _frontView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; - [self reloadShadow]; - - [self addSubview:_frontView]; - } - return self; + self = [super initWithFrame:frame]; + if ( self ) + { + _c = controller; + CGRect bounds = self.bounds; + + _frontView = [[UIView alloc] initWithFrame:bounds]; + _frontView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; + [self reloadShadow]; + + [self addSubview:_frontView]; + } + return self; } - (void)reloadShadow { - CALayer *frontViewLayer = _frontView.layer; - frontViewLayer.shadowColor = [_c.frontViewShadowColor CGColor]; - frontViewLayer.shadowOpacity = _c.frontViewShadowOpacity; - frontViewLayer.shadowOffset = _c.frontViewShadowOffset; - frontViewLayer.shadowRadius = _c.frontViewShadowRadius; + CALayer *frontViewLayer = _frontView.layer; + frontViewLayer.shadowColor = [_c.frontViewShadowColor CGColor]; + frontViewLayer.shadowOpacity = _c.frontViewShadowOpacity; + frontViewLayer.shadowOffset = _c.frontViewShadowOffset; + frontViewLayer.shadowRadius = _c.frontViewShadowRadius; } - (CGRect)hierarchycalFrameAdjustment:(CGRect)frame { - if ( _c.presentFrontViewHierarchically ) - { - UINavigationBar *dummyBar = [[UINavigationBar alloc] init]; - CGFloat barHeight = [dummyBar sizeThatFits:CGSizeMake(100,100)].height; - CGFloat offset = barHeight + statusBarAdjustment(self); - frame.origin.y += offset; - frame.size.height -= offset; - } - return frame; + if ( _c.presentFrontViewHierarchically ) + { + UINavigationBar *dummyBar = [[UINavigationBar alloc] init]; + CGFloat barHeight = [dummyBar sizeThatFits:CGSizeMake(100,100)].height; + CGFloat offset = barHeight + statusBarAdjustment(self); + frame.origin.y += offset; + frame.size.height -= offset; + } + return frame; } - (void)prepareRearViewForPosition:(FrontViewPosition)newPosition { - if ( _rearView == nil ) - { - _rearView = [[UIView alloc] initWithFrame:self.bounds]; - _rearView.autoresizingMask = /*UIViewAutoresizingFlexibleWidth|*/UIViewAutoresizingFlexibleHeight; - [self insertSubview:_rearView belowSubview:_frontView]; - } - - CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; - [self _layoutRearViewsForLocation:xLocation]; - [self _prepareForNewPosition:newPosition]; + if ( _rearView == nil ) + { + _rearView = [[UIView alloc] initWithFrame:self.bounds]; + _rearView.autoresizingMask = /*UIViewAutoresizingFlexibleWidth|*/UIViewAutoresizingFlexibleHeight; + [self insertSubview:_rearView belowSubview:_frontView]; + } + + CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; + [self _layoutRearViewsForLocation:xLocation]; + [self _prepareForNewPosition:newPosition]; } - (void)prepareRightViewForPosition:(FrontViewPosition)newPosition { - if ( _rightView == nil ) - { - _rightView = [[UIView alloc] initWithFrame:self.bounds]; - _rightView.autoresizingMask = /*UIViewAutoresizingFlexibleWidth|*/UIViewAutoresizingFlexibleHeight; - [self insertSubview:_rightView belowSubview:_frontView]; - } - - CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; - [self _layoutRearViewsForLocation:xLocation]; - [self _prepareForNewPosition:newPosition]; + if ( _rightView == nil ) + { + _rightView = [[UIView alloc] initWithFrame:self.bounds]; + _rightView.autoresizingMask = /*UIViewAutoresizingFlexibleWidth|*/UIViewAutoresizingFlexibleHeight; + [self insertSubview:_rightView belowSubview:_frontView]; + } + + CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition]; + [self _layoutRearViewsForLocation:xLocation]; + [self _prepareForNewPosition:newPosition]; } - (void)unloadRearView { - [_rearView removeFromSuperview]; - _rearView = nil; + [_rearView removeFromSuperview]; + _rearView = nil; } - (void)unloadRightView { - [_rightView removeFromSuperview]; - _rightView = nil; + [_rightView removeFromSuperview]; + _rightView = nil; } - (CGFloat)frontLocationForPosition:(FrontViewPosition)frontViewPosition { - CGFloat revealWidth; - CGFloat revealOverdraw; - - CGFloat location = 0.0f; - - int symetry = frontViewPosition FrontViewPositionRight ) - location = revealWidth + revealOverdraw; - - return location*symetry; + CGFloat revealWidth; + CGFloat revealOverdraw; + + CGFloat location = 0.0f; + + int symetry = frontViewPosition FrontViewPositionRight ) + location = revealWidth + revealOverdraw; + + return location*symetry; } - (void)dragFrontViewToXLocation:(CGFloat)xLocation { - CGRect bounds = self.bounds; - - xLocation = [self _adjustedDragLocationForLocation:xLocation]; - [self _layoutRearViewsForLocation:xLocation]; - - CGRect frame = CGRectMake(xLocation, 0.0f, bounds.size.width, bounds.size.height); - _frontView.frame = [self hierarchycalFrameAdjustment:frame]; + CGRect bounds = self.bounds; + + xLocation = [self _adjustedDragLocationForLocation:xLocation]; + [self _layoutRearViewsForLocation:xLocation]; + + CGRect frame = CGRectMake(xLocation, 0.0f, bounds.size.width, bounds.size.height); + _frontView.frame = [self hierarchycalFrameAdjustment:frame]; } @@ -205,76 +205,76 @@ - (void)dragFrontViewToXLocation:(CGFloat)xLocation - (void)layoutSubviews { - if ( _disableLayout ) return; - - CGRect bounds = self.bounds; - - FrontViewPosition position = _c.frontViewPosition; - CGFloat xLocation = [self frontLocationForPosition:position]; - - // set rear view frames - [self _layoutRearViewsForLocation:xLocation]; - - // set front view frame - CGRect frame = CGRectMake(xLocation, 0.0f, bounds.size.width, bounds.size.height); - _frontView.frame = [self hierarchycalFrameAdjustment:frame]; - - // setup front view shadow path if needed (front view loaded and not removed) - UIViewController *frontViewController = _c.frontViewController; - BOOL viewLoaded = frontViewController != nil && frontViewController.isViewLoaded; - BOOL viewNotRemoved = position > FrontViewPositionLeftSideMostRemoved && position < FrontViewPositionRightMostRemoved; - CGRect shadowBounds = viewLoaded && viewNotRemoved ? _frontView.bounds : CGRectZero; - - UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:shadowBounds]; - _frontView.layer.shadowPath = shadowPath.CGPath; + if ( _disableLayout ) return; + + CGRect bounds = self.bounds; + + FrontViewPosition position = _c.frontViewPosition; + CGFloat xLocation = [self frontLocationForPosition:position]; + + // set rear view frames + [self _layoutRearViewsForLocation:xLocation]; + + // set front view frame + CGRect frame = CGRectMake(xLocation, 0.0f, bounds.size.width, bounds.size.height); + _frontView.frame = [self hierarchycalFrameAdjustment:frame]; + + // setup front view shadow path if needed (front view loaded and not removed) + UIViewController *frontViewController = _c.frontViewController; + BOOL viewLoaded = frontViewController != nil && frontViewController.isViewLoaded; + BOOL viewNotRemoved = position > FrontViewPositionLeftSideMostRemoved && position < FrontViewPositionRightMostRemoved; + CGRect shadowBounds = viewLoaded && viewNotRemoved ? _frontView.bounds : CGRectZero; + + UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:shadowBounds]; + _frontView.layer.shadowPath = shadowPath.CGPath; } - (BOOL)pointInsideD:(CGPoint)point withEvent:(UIEvent *)event { - BOOL isInside = [super pointInside:point withEvent:event]; - if ( _c.extendsPointInsideHit ) - { - if ( !isInside && _rearView && [_c.rearViewController isViewLoaded] ) - { - CGPoint pt = [self convertPoint:point toView:_rearView]; - isInside = [_rearView pointInside:pt withEvent:event]; - } - - if ( !isInside && _frontView && [_c.frontViewController isViewLoaded] ) - { - CGPoint pt = [self convertPoint:point toView:_frontView]; - isInside = [_frontView pointInside:pt withEvent:event]; - } - - if ( !isInside && _rightView && [_c.rightViewController isViewLoaded] ) - { - CGPoint pt = [self convertPoint:point toView:_rightView]; - isInside = [_rightView pointInside:pt withEvent:event]; - } - } - return isInside; + BOOL isInside = [super pointInside:point withEvent:event]; + if ( _c.extendsPointInsideHit ) + { + if ( !isInside && _rearView && [_c.rearViewController isViewLoaded] ) + { + CGPoint pt = [self convertPoint:point toView:_rearView]; + isInside = [_rearView pointInside:pt withEvent:event]; + } + + if ( !isInside && _frontView && [_c.frontViewController isViewLoaded] ) + { + CGPoint pt = [self convertPoint:point toView:_frontView]; + isInside = [_frontView pointInside:pt withEvent:event]; + } + + if ( !isInside && _rightView && [_c.rightViewController isViewLoaded] ) + { + CGPoint pt = [self convertPoint:point toView:_rightView]; + isInside = [_rightView pointInside:pt withEvent:event]; + } + } + return isInside; } - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { - BOOL isInside = [super pointInside:point withEvent:event]; - if ( !isInside && _c.extendsPointInsideHit ) - { - UIView *testViews[] = { _rearView, _frontView, _rightView }; - UIViewController *testControllers[] = { _c.rearViewController, _c.frontViewController, _c.rightViewController }; - - for ( NSInteger i=0 ; i<3 && !isInside ; i++ ) - { - if ( testViews[i] && [testControllers[i] isViewLoaded] ) - { - CGPoint pt = [self convertPoint:point toView:testViews[i]]; - isInside = [testViews[i] pointInside:pt withEvent:event]; - } - } - } - return isInside; + BOOL isInside = [super pointInside:point withEvent:event]; + if ( !isInside && _c.extendsPointInsideHit ) + { + UIView *testViews[] = { _rearView, _frontView, _rightView }; + UIViewController *testControllers[] = { _c.rearViewController, _c.frontViewController, _c.rightViewController }; + + for ( NSInteger i=0 ; i<3 && !isInside ; i++ ) + { + if ( testViews[i] && [testControllers[i] isViewLoaded] ) + { + CGPoint pt = [self convertPoint:point toView:testViews[i]]; + isInside = [testViews[i] pointInside:pt withEvent:event]; + } + } + } + return isInside; } @@ -283,76 +283,76 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event - (void)_layoutRearViewsForLocation:(CGFloat)xLocation { - CGRect bounds = self.bounds; - - CGFloat rearRevealWidth = _c.rearViewRevealWidth; - if ( rearRevealWidth < 0) rearRevealWidth = bounds.size.width + _c.rearViewRevealWidth; - - CGFloat rearXLocation = scaledValue(xLocation, -_c.rearViewRevealDisplacement, 0, 0, rearRevealWidth); - - CGFloat rearWidth = rearRevealWidth + _c.rearViewRevealOverdraw; - _rearView.frame = CGRectMake(rearXLocation, 0.0, rearWidth, bounds.size.height); - - CGFloat rightRevealWidth = _c.rightViewRevealWidth; - if ( rightRevealWidth < 0) rightRevealWidth = bounds.size.width + _c.rightViewRevealWidth; - - CGFloat rightXLocation = scaledValue(xLocation, 0, _c.rightViewRevealDisplacement, -rightRevealWidth, 0); - - CGFloat rightWidth = rightRevealWidth + _c.rightViewRevealOverdraw; - _rightView.frame = CGRectMake(bounds.size.width-rightWidth+rightXLocation, 0.0f, rightWidth, bounds.size.height); + CGRect bounds = self.bounds; + + CGFloat rearRevealWidth = _c.rearViewRevealWidth; + if ( rearRevealWidth < 0) rearRevealWidth = bounds.size.width + _c.rearViewRevealWidth; + + CGFloat rearXLocation = scaledValue(xLocation, -_c.rearViewRevealDisplacement, 0, 0, rearRevealWidth); + + CGFloat rearWidth = rearRevealWidth + _c.rearViewRevealOverdraw; + _rearView.frame = CGRectMake(rearXLocation, 0.0, rearWidth, bounds.size.height); + + CGFloat rightRevealWidth = _c.rightViewRevealWidth; + if ( rightRevealWidth < 0) rightRevealWidth = bounds.size.width + _c.rightViewRevealWidth; + + CGFloat rightXLocation = scaledValue(xLocation, 0, _c.rightViewRevealDisplacement, -rightRevealWidth, 0); + + CGFloat rightWidth = rightRevealWidth + _c.rightViewRevealOverdraw; + _rightView.frame = CGRectMake(bounds.size.width-rightWidth+rightXLocation, 0.0f, rightWidth, bounds.size.height); } - (void)_prepareForNewPosition:(FrontViewPosition)newPosition; { - if ( _rearView == nil || _rightView == nil ) - return; - - int symetry = newPosition 0 && rearIndex < rightIndex) ) - [self exchangeSubviewAtIndex:rightIndex withSubviewAtIndex:rearIndex]; + if ( _rearView == nil || _rightView == nil ) + return; + + int symetry = newPosition 0 && rearIndex < rightIndex) ) + [self exchangeSubviewAtIndex:rightIndex withSubviewAtIndex:rearIndex]; } - (CGFloat)_adjustedDragLocationForLocation:(CGFloat)x { - CGFloat result; - - CGFloat revealWidth; - CGFloat revealOverdraw; - BOOL bounceBack; - BOOL stableDrag; - FrontViewPosition position = _c.frontViewPosition; - - int symetry = x<0 ? -1 : 1; - - [_c _getRevealWidth:&revealWidth revealOverDraw:&revealOverdraw forSymetry:symetry]; - [_c _getBounceBack:&bounceBack pStableDrag:&stableDrag forSymetry:symetry]; - - BOOL stableTrack = !bounceBack || stableDrag || position==FrontViewPositionRightMost || position==FrontViewPositionLeftSideMost; - if ( stableTrack ) - { - revealWidth += revealOverdraw; - revealOverdraw = 0.0f; - } - - x = x * symetry; - - if (x <= revealWidth) - result = x; // Translate linearly. - - else if (x <= revealWidth+2*revealOverdraw) - result = revealWidth + (x-revealWidth)/2; // slow down translation by halph the movement. - - else - result = revealWidth+revealOverdraw; // keep at the rightMost location. - - return result * symetry; + CGFloat result; + + CGFloat revealWidth; + CGFloat revealOverdraw; + BOOL bounceBack; + BOOL stableDrag; + FrontViewPosition position = _c.frontViewPosition; + + int symetry = x<0 ? -1 : 1; + + [_c _getRevealWidth:&revealWidth revealOverDraw:&revealOverdraw forSymetry:symetry]; + [_c _getBounceBack:&bounceBack pStableDrag:&stableDrag forSymetry:symetry]; + + BOOL stableTrack = !bounceBack || stableDrag || position==FrontViewPositionRightMost || position==FrontViewPositionLeftSideMost; + if ( stableTrack ) + { + revealWidth += revealOverdraw; + revealOverdraw = 0.0f; + } + + x = x * symetry; + + if (x <= revealWidth) + result = x; // Translate linearly. + + else if (x <= revealWidth+2*revealOverdraw) + result = revealWidth + (x-revealWidth)/2; // slow down translation by halph the movement. + + else + result = revealWidth+revealOverdraw; // keep at the rightMost location. + + return result * symetry; } @end @@ -366,119 +366,124 @@ @interface SWContextTransitionObject : NSObject)transitionContext { - return _duration; + return _duration; } - (void)animateTransition:(id )transitionContext { - UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; - UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; - - if ( fromViewController ) - { - [UIView transitionFromView:fromViewController.view toView:toViewController.view duration:_duration - options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionOverrideInheritedOptions - completion:^(BOOL finished) { [transitionContext completeTransition:finished]; }]; - } - else - { - // tansitionFromView does not correctly handle the case where the fromView is nil (at least on iOS7) it just pops up the toView view with no animation, - // so in such case we replace the crossDissolve animation by a simple alpha animation on the appearing view - UIView *toView = toViewController.view; - CGFloat alpha = toView.alpha; - toView.alpha = 0; - - [UIView animateWithDuration:_duration delay:0 options:UIViewAnimationOptionCurveEaseOut - animations:^{ toView.alpha = alpha;} - completion:^(BOOL finished) { [transitionContext completeTransition:finished];}]; - } + UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; + UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; + + if ( fromViewController ) + { + [UIView transitionFromView:fromViewController.view toView:toViewController.view duration:_duration + options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionOverrideInheritedOptions + completion:^(BOOL finished) { [transitionContext completeTransition:finished]; }]; + } + else + { + // tansitionFromView does not correctly handle the case where the fromView is nil (at least on iOS7) it just pops up the toView view with no animation, + // so in such case we replace the crossDissolve animation by a simple alpha animation on the appearing view + UIView *toView = toViewController.view; + CGFloat alpha = toView.alpha; + toView.alpha = 0; + + [UIView animateWithDuration:_duration delay:0 options:UIViewAnimationOptionCurveEaseOut + animations:^{ toView.alpha = alpha;} + completion:^(BOOL finished) { [transitionContext completeTransition:finished];}]; + } } @end @@ -547,34 +552,34 @@ @interface SWRevealViewControllerPanGestureRecognizer : UIPanGestureRecognizer @implementation SWRevealViewControllerPanGestureRecognizer { - BOOL _dragging; - CGPoint _beginPoint; + BOOL _dragging; + CGPoint _beginPoint; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - [super touchesBegan:touches withEvent:event]; - - UITouch *touch = [touches anyObject]; - _beginPoint = [touch locationInView:self.view]; - _dragging = NO; + [super touchesBegan:touches withEvent:event]; + + UITouch *touch = [touches anyObject]; + _beginPoint = [touch locationInView:self.view]; + _dragging = NO; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - [super touchesMoved:touches withEvent:event]; - - if ( _dragging || self.state == UIGestureRecognizerStateFailed) - return; - - const CGFloat kDirectionPanThreshold = 5; - - UITouch *touch = [touches anyObject]; - CGPoint nowPoint = [touch locationInView:self.view]; - - if (ABS(nowPoint.x - _beginPoint.x) > kDirectionPanThreshold) _dragging = YES; - else if (ABS(nowPoint.y - _beginPoint.y) > kDirectionPanThreshold) self.state = UIGestureRecognizerStateFailed; + [super touchesMoved:touches withEvent:event]; + + if ( _dragging || self.state == UIGestureRecognizerStateFailed) + return; + + const CGFloat kDirectionPanThreshold = 5; + + UITouch *touch = [touches anyObject]; + CGPoint nowPoint = [touch locationInView:self.view]; + + if (ABS(nowPoint.x - _beginPoint.x) > kDirectionPanThreshold) _dragging = YES; + else if (ABS(nowPoint.y - _beginPoint.y) > kDirectionPanThreshold) self.state = UIGestureRecognizerStateFailed; } @end @@ -584,24 +589,24 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event @interface SWRevealViewController() { - SWRevealView *_contentView; - UIPanGestureRecognizer *_panGestureRecognizer; - UITapGestureRecognizer *_tapGestureRecognizer; - FrontViewPosition _frontViewPosition; - FrontViewPosition _rearViewPosition; - FrontViewPosition _rightViewPosition; - SWContextTransitionObject *_rearTransitioningController; - SWContextTransitionObject *_frontTransitioningController; - SWContextTransitionObject *_rightTransitioningController; + SWRevealView *_contentView; + UIPanGestureRecognizer *_panGestureRecognizer; + UITapGestureRecognizer *_tapGestureRecognizer; + FrontViewPosition _frontViewPosition; + FrontViewPosition _rearViewPosition; + FrontViewPosition _rightViewPosition; + SWContextTransitionObject *_rearTransitioningController; + SWContextTransitionObject *_frontTransitioningController; + SWContextTransitionObject *_rightTransitioningController; } @end @implementation SWRevealViewController { - FrontViewPosition _panInitialFrontPosition; - NSMutableArray *_animationQueue; - BOOL _userInteractionStore; + FrontViewPosition _panInitialFrontPosition; + NSMutableArray *_animationQueue; + BOOL _userInteractionStore; } const int FrontViewPositionNone = 0xff; @@ -611,64 +616,64 @@ @implementation SWRevealViewController - (id)initWithCoder:(NSCoder *)aDecoder { - self = [super initWithCoder:aDecoder]; - if ( self ) - { - [self _initDefaultProperties]; - } - return self; + self = [super initWithCoder:aDecoder]; + if ( self ) + { + [self _initDefaultProperties]; + } + return self; } - (id)init { - return [self initWithRearViewController:nil frontViewController:nil]; + return [self initWithRearViewController:nil frontViewController:nil]; } - (id)initWithRearViewController:(UIViewController *)rearViewController frontViewController:(UIViewController *)frontViewController; { - self = [super init]; - if ( self ) - { - [self _initDefaultProperties]; - [self _performTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:NO]; - [self _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO]; - } - return self; + self = [super init]; + if ( self ) + { + [self _initDefaultProperties]; + [self _performTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:NO]; + [self _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO]; + } + return self; } - (void)_initDefaultProperties { - _frontViewPosition = FrontViewPositionLeft; - _rearViewPosition = FrontViewPositionLeft; - _rightViewPosition = FrontViewPositionLeft; - _rearViewRevealWidth = 260.0f; - _rearViewRevealOverdraw = 60.0f; - _rearViewRevealDisplacement = 40.0f; - _rightViewRevealWidth = 260.0f; - _rightViewRevealOverdraw = 60.0f; - _rightViewRevealDisplacement = 40.0f; - _bounceBackOnOverdraw = YES; - _bounceBackOnLeftOverdraw = YES; - _stableDragOnOverdraw = NO; - _stableDragOnLeftOverdraw = NO; - _presentFrontViewHierarchically = NO; - _quickFlickVelocity = 250.0f; - _toggleAnimationDuration = 0.3; - _toggleAnimationType = SWRevealToggleAnimationTypeSpring; - _springDampingRatio = 1; - _replaceViewAnimationDuration = 0.25; - _frontViewShadowRadius = 2.5f; - _frontViewShadowOffset = CGSizeMake(0.0f, 2.5f); - _frontViewShadowOpacity = 1.0f; - _frontViewShadowColor = [UIColor blackColor]; - _userInteractionStore = YES; - _animationQueue = [NSMutableArray array]; - _draggableBorderWidth = 0.0f; - _clipsViewsToBounds = NO; - _extendsPointInsideHit = NO; + _frontViewPosition = FrontViewPositionLeft; + _rearViewPosition = FrontViewPositionLeft; + _rightViewPosition = FrontViewPositionLeft; + _rearViewRevealWidth = 260.0f; + _rearViewRevealOverdraw = 60.0f; + _rearViewRevealDisplacement = 40.0f; + _rightViewRevealWidth = 260.0f; + _rightViewRevealOverdraw = 60.0f; + _rightViewRevealDisplacement = 40.0f; + _bounceBackOnOverdraw = YES; + _bounceBackOnLeftOverdraw = YES; + _stableDragOnOverdraw = NO; + _stableDragOnLeftOverdraw = NO; + _presentFrontViewHierarchically = NO; + _quickFlickVelocity = 250.0f; + _toggleAnimationDuration = 0.3; + _toggleAnimationType = SWRevealToggleAnimationTypeSpring; + _springDampingRatio = 1; + _replaceViewAnimationDuration = 0.25; + _frontViewShadowRadius = 2.5f; + _frontViewShadowOffset = CGSizeMake(0.0f, 2.5f); + _frontViewShadowOpacity = 1.0f; + _frontViewShadowColor = [UIColor blackColor]; + _userInteractionStore = YES; + _animationQueue = [NSMutableArray array]; + _draggableBorderWidth = 0.0f; + _clipsViewsToBounds = NO; + _extendsPointInsideHit = NO; } @@ -676,19 +681,19 @@ - (void)_initDefaultProperties - (UIViewController *)childViewControllerForStatusBarStyle { - int positionDif = _frontViewPosition - FrontViewPositionLeft; - - UIViewController *controller = _frontViewController; - if ( positionDif > 0 ) controller = _rearViewController; - else if ( positionDif < 0 ) controller = _rightViewController; - - return controller; + int positionDif = _frontViewPosition - FrontViewPositionLeft; + + UIViewController *controller = _frontViewController; + if ( positionDif > 0 ) controller = _rearViewController; + else if ( positionDif < 0 ) controller = _rightViewController; + + return controller; } - (UIViewController *)childViewControllerForStatusBarHidden { - UIViewController *controller = [self childViewControllerForStatusBarStyle]; - return controller; + UIViewController *controller = [self childViewControllerForStatusBarStyle]; + return controller; } @@ -696,247 +701,247 @@ - (UIViewController *)childViewControllerForStatusBarHidden - (void)loadView { - // Do not call super, to prevent the apis from unfruitful looking for inexistent xibs! - //[super loadView]; - - // load any defined front/rear controllers from the storyboard before - [self loadStoryboardControllers]; - - // This is what Apple used to tell us to set as the initial frame, which is of course totally irrelevant - // with view controller containment patterns, let's leave it for the sake of it! - // CGRect frame = [[UIScreen mainScreen] applicationFrame]; - - // On iOS7 the applicationFrame does not return the whole screen. This is possibly a bug. - // As a workaround we use the screen bounds, this still works on iOS6, any zero based frame would work anyway! - CGRect frame = [[UIScreen mainScreen] bounds]; - - // create a custom content view for the controller - _contentView = [[SWRevealView alloc] initWithFrame:frame controller:self]; - - // set the content view to resize along with its superview - [_contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; - - // set the content view to clip its bounds if requested - [_contentView setClipsToBounds:_clipsViewsToBounds]; - - // set our contentView to the controllers view - self.view = _contentView; - - // Apple also tells us to do this: - _contentView.backgroundColor = [UIColor blackColor]; - - // we set the current frontViewPosition to none before seting the - // desired initial position, this will force proper controller reload - FrontViewPosition initialPosition = _frontViewPosition; - _frontViewPosition = FrontViewPositionNone; - _rearViewPosition = FrontViewPositionNone; - _rightViewPosition = FrontViewPositionNone; - - // now set the desired initial position - [self _setFrontViewPosition:initialPosition withDuration:0.0]; + // Do not call super, to prevent the apis from unfruitful looking for inexistent xibs! + //[super loadView]; + + // load any defined front/rear controllers from the storyboard before + [self loadStoryboardControllers]; + + // This is what Apple used to tell us to set as the initial frame, which is of course totally irrelevant + // with view controller containment patterns, let's leave it for the sake of it! + // CGRect frame = [[UIScreen mainScreen] applicationFrame]; + + // On iOS7 the applicationFrame does not return the whole screen. This is possibly a bug. + // As a workaround we use the screen bounds, this still works on iOS6, any zero based frame would work anyway! + CGRect frame = [[UIScreen mainScreen] bounds]; + + // create a custom content view for the controller + _contentView = [[SWRevealView alloc] initWithFrame:frame controller:self]; + + // set the content view to resize along with its superview + [_contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; + + // set the content view to clip its bounds if requested + [_contentView setClipsToBounds:_clipsViewsToBounds]; + + // set our contentView to the controllers view + self.view = _contentView; + + // Apple also tells us to do this: + _contentView.backgroundColor = [UIColor blackColor]; + + // we set the current frontViewPosition to none before seting the + // desired initial position, this will force proper controller reload + FrontViewPosition initialPosition = _frontViewPosition; + _frontViewPosition = FrontViewPositionNone; + _rearViewPosition = FrontViewPositionNone; + _rightViewPosition = FrontViewPositionNone; + + // now set the desired initial position + [self _setFrontViewPosition:initialPosition withDuration:0.0]; } - (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - - // Uncomment the following code if you want the child controllers - // to be loaded at this point. - // - // We leave this commented out because we think loading childs here is conceptually wrong. - // Instead, we refrain view loads until necesary, for example we may never load - // the rear controller view -or the front controller view- if it is never displayed. - // - // If you need to manipulate views of any of your child controllers in an override - // of this method, you can load yourself the views explicitly on your overriden method. - // However we discourage it as an app following the MVC principles should never need to do so - -// [_frontViewController view]; -// [_rearViewController view]; - - // we store at this point the view's user interaction state as we may temporarily disable it - // and resume it back to the previous state, it is possible to override this behaviour by - // intercepting it on the panGestureBegan and panGestureEnded delegates - _userInteractionStore = _contentView.userInteractionEnabled; -} - - -- (NSUInteger)supportedInterfaceOrientations -{ - // we could have simply not implemented this, but we choose to call super to make explicit that we - // want the default behavior. - return [super supportedInterfaceOrientations]; -} + [super viewDidAppear:animated]; + + // Uncomment the following code if you want the child controllers + // to be loaded at this point. + // + // We leave this commented out because we think loading childs here is conceptually wrong. + // Instead, we refrain view loads until necesary, for example we may never load + // the rear controller view -or the front controller view- if it is never displayed. + // + // If you need to manipulate views of any of your child controllers in an override + // of this method, you can load yourself the views explicitly on your overriden method. + // However we discourage it as an app following the MVC principles should never need to do so + + // [_frontViewController view]; + // [_rearViewController view]; + + // we store at this point the view's user interaction state as we may temporarily disable it + // and resume it back to the previous state, it is possible to override this behaviour by + // intercepting it on the panGestureBegan and panGestureEnded delegates + _userInteractionStore = _contentView.userInteractionEnabled; +} + + +//- (NSUInteger)supportedInterfaceOrientations +//{ +// // we could have simply not implemented this, but we choose to call super to make explicit that we +// // want the default behavior. +// return [super supportedInterfaceOrientations]; +//} #pragma mark - Public methods and property accessors - (void)setFrontViewController:(UIViewController *)frontViewController { - [self setFrontViewController:frontViewController animated:NO]; + [self setFrontViewController:frontViewController animated:NO]; } - (void)setFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated { - if ( ![self isViewLoaded]) - { - [self _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO]; - return; - } - - [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:animated]; + if ( ![self isViewLoaded]) + { + [self _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO]; + return; + } + + [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:animated]; } - (void)pushFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated { - if ( ![self isViewLoaded]) - { - [self _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO]; - return; - } - - [self _dispatchPushFrontViewController:frontViewController animated:animated]; + if ( ![self isViewLoaded]) + { + [self _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO]; + return; + } + + [self _dispatchPushFrontViewController:frontViewController animated:animated]; } - (void)setRearViewController:(UIViewController *)rearViewController { - [self setRearViewController:rearViewController animated:NO]; + [self setRearViewController:rearViewController animated:NO]; } - (void)setRearViewController:(UIViewController *)rearViewController animated:(BOOL)animated { - if ( ![self isViewLoaded]) - { - [self _performTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:NO]; - return; - } - - [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:animated]; + if ( ![self isViewLoaded]) + { + [self _performTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:NO]; + return; + } + + [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:animated]; } - (void)setRightViewController:(UIViewController *)rightViewController { - [self setRightViewController:rightViewController animated:NO]; + [self setRightViewController:rightViewController animated:NO]; } - (void)setRightViewController:(UIViewController *)rightViewController animated:(BOOL)animated { - if ( ![self isViewLoaded]) - { - [self _performTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:NO]; - return; - } - - [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:animated]; + if ( ![self isViewLoaded]) + { + [self _performTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:NO]; + return; + } + + [self _dispatchTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:animated]; } - (void)revealToggleAnimated:(BOOL)animated { - FrontViewPosition toggledFrontViewPosition = FrontViewPositionLeft; - if (_frontViewPosition <= FrontViewPositionLeft) - toggledFrontViewPosition = FrontViewPositionRight; - - [self setFrontViewPosition:toggledFrontViewPosition animated:animated]; + FrontViewPosition toggledFrontViewPosition = FrontViewPositionLeft; + if (_frontViewPosition <= FrontViewPositionLeft) + toggledFrontViewPosition = FrontViewPositionRight; + + [self setFrontViewPosition:toggledFrontViewPosition animated:animated]; } - (void)rightRevealToggleAnimated:(BOOL)animated { - FrontViewPosition toggledFrontViewPosition = FrontViewPositionLeft; - if (_frontViewPosition >= FrontViewPositionLeft) - toggledFrontViewPosition = FrontViewPositionLeftSide; - - [self setFrontViewPosition:toggledFrontViewPosition animated:animated]; + FrontViewPosition toggledFrontViewPosition = FrontViewPositionLeft; + if (_frontViewPosition >= FrontViewPositionLeft) + toggledFrontViewPosition = FrontViewPositionLeftSide; + + [self setFrontViewPosition:toggledFrontViewPosition animated:animated]; } - (void)setFrontViewPosition:(FrontViewPosition)frontViewPosition { - [self setFrontViewPosition:frontViewPosition animated:NO]; + [self setFrontViewPosition:frontViewPosition animated:NO]; } - (void)setFrontViewPosition:(FrontViewPosition)frontViewPosition animated:(BOOL)animated { - if ( ![self isViewLoaded] ) - { - _frontViewPosition = frontViewPosition; - _rearViewPosition = frontViewPosition; - _rightViewPosition = frontViewPosition; - return; - } - - [self _dispatchSetFrontViewPosition:frontViewPosition animated:animated]; + if ( ![self isViewLoaded] ) + { + _frontViewPosition = frontViewPosition; + _rearViewPosition = frontViewPosition; + _rightViewPosition = frontViewPosition; + return; + } + + [self _dispatchSetFrontViewPosition:frontViewPosition animated:animated]; } - (void)setFrontViewShadowRadius:(CGFloat)frontViewShadowRadius { - _frontViewShadowRadius = frontViewShadowRadius; - [_contentView reloadShadow]; + _frontViewShadowRadius = frontViewShadowRadius; + [_contentView reloadShadow]; } - (void)setFrontViewShadowOffset:(CGSize)frontViewShadowOffset { - _frontViewShadowOffset = frontViewShadowOffset; - [_contentView reloadShadow]; + _frontViewShadowOffset = frontViewShadowOffset; + [_contentView reloadShadow]; } - (void)setFrontViewShadowOpacity:(CGFloat)frontViewShadowOpacity { - _frontViewShadowOpacity = frontViewShadowOpacity; - [_contentView reloadShadow]; + _frontViewShadowOpacity = frontViewShadowOpacity; + [_contentView reloadShadow]; } - (void)setFrontViewShadowColor:(UIColor *)frontViewShadowColor { - _frontViewShadowColor = frontViewShadowColor; - [_contentView reloadShadow]; + _frontViewShadowColor = frontViewShadowColor; + [_contentView reloadShadow]; } - (UIPanGestureRecognizer*)panGestureRecognizer { - if ( _panGestureRecognizer == nil ) - { - _panGestureRecognizer = [[SWRevealViewControllerPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleRevealGesture:)]; - _panGestureRecognizer.delegate = self; - [_contentView.frontView addGestureRecognizer:_panGestureRecognizer]; - } - return _panGestureRecognizer; + if ( _panGestureRecognizer == nil ) + { + _panGestureRecognizer = [[SWRevealViewControllerPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleRevealGesture:)]; + _panGestureRecognizer.delegate = self; + [_contentView.frontView addGestureRecognizer:_panGestureRecognizer]; + } + return _panGestureRecognizer; } - (UITapGestureRecognizer*)tapGestureRecognizer { - if ( _tapGestureRecognizer == nil ) - { - UITapGestureRecognizer *tapRecognizer = - [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTapGesture:)]; - - tapRecognizer.delegate = self; - [_contentView.frontView addGestureRecognizer:tapRecognizer]; - _tapGestureRecognizer = tapRecognizer ; - } - return _tapGestureRecognizer; + if ( _tapGestureRecognizer == nil ) + { + UITapGestureRecognizer *tapRecognizer = + [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTapGesture:)]; + + tapRecognizer.delegate = self; + [_contentView.frontView addGestureRecognizer:tapRecognizer]; + _tapGestureRecognizer = tapRecognizer ; + } + return _tapGestureRecognizer; } - (void)setClipsViewsToBounds:(BOOL)clipsViewsToBounds { - _clipsViewsToBounds = clipsViewsToBounds; - [_contentView setClipsToBounds:clipsViewsToBounds]; + _clipsViewsToBounds = clipsViewsToBounds; + [_contentView setClipsToBounds:clipsViewsToBounds]; } @@ -944,14 +949,14 @@ - (void)setClipsViewsToBounds:(BOOL)clipsViewsToBounds #pragma mark - Provided acction methods - (IBAction)revealToggle:(id)sender -{ - [self revealToggleAnimated:YES]; +{ + [self revealToggleAnimated:YES]; } - (IBAction)rightRevealToggle:(id)sender -{ - [self rightRevealToggleAnimated:YES]; +{ + [self rightRevealToggleAnimated:YES]; } @@ -960,17 +965,17 @@ - (IBAction)rightRevealToggle:(id)sender // disable userInteraction on the entire control - (void)_disableUserInteraction { - [_contentView setUserInteractionEnabled:NO]; - [_contentView setDisableLayout:YES]; + [_contentView setUserInteractionEnabled:NO]; + [_contentView setDisableLayout:YES]; } // restore userInteraction on the control - (void)_restoreUserInteraction { - // we use the stored userInteraction state just in case a developer decided - // to have our view interaction disabled beforehand - [_contentView setUserInteractionEnabled:_userInteractionStore]; - [_contentView setDisableLayout:NO]; + // we use the stored userInteraction state just in case a developer decided + // to have our view interaction disabled beforehand + [_contentView setUserInteractionEnabled:_userInteractionStore]; + [_contentView setDisableLayout:NO]; } @@ -978,44 +983,44 @@ - (void)_restoreUserInteraction - (void)_notifyPanGestureBegan { - if ( [_delegate respondsToSelector:@selector(revealControllerPanGestureBegan:)] ) - [_delegate revealControllerPanGestureBegan:self]; - - CGFloat xLocation, dragProgress, overProgress; - [self _getDragLocation:&xLocation progress:&dragProgress overdrawProgress:&overProgress]; - - if ( [_delegate respondsToSelector:@selector(revealController:panGestureBeganFromLocation:progress:overProgress:)] ) - [_delegate revealController:self panGestureBeganFromLocation:xLocation progress:dragProgress overProgress:overProgress]; - - else if ( [_delegate respondsToSelector:@selector(revealController:panGestureBeganFromLocation:progress:)] ) - [_delegate revealController:self panGestureBeganFromLocation:xLocation progress:dragProgress]; + if ( [_delegate respondsToSelector:@selector(revealControllerPanGestureBegan:)] ) + [_delegate revealControllerPanGestureBegan:self]; + + CGFloat xLocation, dragProgress, overProgress; + [self _getDragLocation:&xLocation progress:&dragProgress overdrawProgress:&overProgress]; + + if ( [_delegate respondsToSelector:@selector(revealController:panGestureBeganFromLocation:progress:overProgress:)] ) + [_delegate revealController:self panGestureBeganFromLocation:xLocation progress:dragProgress overProgress:overProgress]; + + else if ( [_delegate respondsToSelector:@selector(revealController:panGestureBeganFromLocation:progress:)] ) + [_delegate revealController:self panGestureBeganFromLocation:xLocation progress:dragProgress]; } - (void)_notifyPanGestureMoved { - CGFloat xLocation, dragProgress, overProgress; - [self _getDragLocation:&xLocation progress:&dragProgress overdrawProgress:&overProgress]; - - if ( [_delegate respondsToSelector:@selector(revealController:panGestureMovedToLocation:progress:overProgress:)] ) - [_delegate revealController:self panGestureMovedToLocation:xLocation progress:dragProgress overProgress:overProgress]; - - else if ( [_delegate respondsToSelector:@selector(revealController:panGestureMovedToLocation:progress:)] ) - [_delegate revealController:self panGestureMovedToLocation:xLocation progress:dragProgress]; + CGFloat xLocation, dragProgress, overProgress; + [self _getDragLocation:&xLocation progress:&dragProgress overdrawProgress:&overProgress]; + + if ( [_delegate respondsToSelector:@selector(revealController:panGestureMovedToLocation:progress:overProgress:)] ) + [_delegate revealController:self panGestureMovedToLocation:xLocation progress:dragProgress overProgress:overProgress]; + + else if ( [_delegate respondsToSelector:@selector(revealController:panGestureMovedToLocation:progress:)] ) + [_delegate revealController:self panGestureMovedToLocation:xLocation progress:dragProgress]; } - (void)_notifyPanGestureEnded { - CGFloat xLocation, dragProgress, overProgress; - [self _getDragLocation:&xLocation progress:&dragProgress overdrawProgress:&overProgress]; - - if ( [_delegate respondsToSelector:@selector(revealController:panGestureEndedToLocation:progress:overProgress:)] ) - [_delegate revealController:self panGestureEndedToLocation:xLocation progress:dragProgress overProgress:overProgress]; - - else if ( [_delegate respondsToSelector:@selector(revealController:panGestureEndedToLocation:progress:)] ) - [_delegate revealController:self panGestureEndedToLocation:xLocation progress:dragProgress]; - - if ( [_delegate respondsToSelector:@selector(revealControllerPanGestureEnded:)] ) - [_delegate revealControllerPanGestureEnded:self]; + CGFloat xLocation, dragProgress, overProgress; + [self _getDragLocation:&xLocation progress:&dragProgress overdrawProgress:&overProgress]; + + if ( [_delegate respondsToSelector:@selector(revealController:panGestureEndedToLocation:progress:overProgress:)] ) + [_delegate revealController:self panGestureEndedToLocation:xLocation progress:dragProgress overProgress:overProgress]; + + else if ( [_delegate respondsToSelector:@selector(revealController:panGestureEndedToLocation:progress:)] ) + [_delegate revealController:self panGestureEndedToLocation:xLocation progress:dragProgress]; + + if ( [_delegate respondsToSelector:@selector(revealControllerPanGestureEnded:)] ) + [_delegate revealControllerPanGestureEnded:self]; } @@ -1023,50 +1028,50 @@ - (void)_notifyPanGestureEnded - (void)_getRevealWidth:(CGFloat*)pRevealWidth revealOverDraw:(CGFloat*)pRevealOverdraw forSymetry:(int)symetry { - if ( symetry < 0 ) *pRevealWidth = _rightViewRevealWidth, *pRevealOverdraw = _rightViewRevealOverdraw; - else *pRevealWidth = _rearViewRevealWidth, *pRevealOverdraw = _rearViewRevealOverdraw; - - if (*pRevealWidth < 0) *pRevealWidth = _contentView.bounds.size.width + *pRevealWidth; + if ( symetry < 0 ) (void)(*pRevealWidth = _rightViewRevealWidth), *pRevealOverdraw = _rightViewRevealOverdraw; + else (void)(*pRevealWidth = _rearViewRevealWidth), *pRevealOverdraw = _rearViewRevealOverdraw; + + if (*pRevealWidth < 0) *pRevealWidth = _contentView.bounds.size.width + *pRevealWidth; } - (void)_getBounceBack:(BOOL*)pBounceBack pStableDrag:(BOOL*)pStableDrag forSymetry:(int)symetry { - if ( symetry < 0 ) *pBounceBack = _bounceBackOnLeftOverdraw, *pStableDrag = _stableDragOnLeftOverdraw; - else *pBounceBack = _bounceBackOnOverdraw, *pStableDrag = _stableDragOnOverdraw; + if ( symetry < 0 ) (void)(*pBounceBack = _bounceBackOnLeftOverdraw), *pStableDrag = _stableDragOnLeftOverdraw; + else (void)(*pBounceBack = _bounceBackOnOverdraw), *pStableDrag = _stableDragOnOverdraw; } - (void)_getAdjustedFrontViewPosition:(FrontViewPosition*)frontViewPosition forSymetry:(int)symetry { - if ( symetry < 0 ) *frontViewPosition = FrontViewPositionLeft + symetry*(*frontViewPosition-FrontViewPositionLeft); + if ( symetry < 0 ) *frontViewPosition = FrontViewPositionLeft + symetry*(*frontViewPosition-FrontViewPositionLeft); } - (void)_getDragLocationx:(CGFloat*)xLocation progress:(CGFloat*)progress { - UIView *frontView = _contentView.frontView; - *xLocation = frontView.frame.origin.x; - - int symetry = *xLocation<0 ? -1 : 1; - - CGFloat xWidth = symetry < 0 ? _rightViewRevealWidth : _rearViewRevealWidth; - if ( xWidth < 0 ) xWidth = _contentView.bounds.size.width + xWidth; - - *progress = *xLocation/xWidth * symetry; + UIView *frontView = _contentView.frontView; + *xLocation = frontView.frame.origin.x; + + int symetry = *xLocation<0 ? -1 : 1; + + CGFloat xWidth = symetry < 0 ? _rightViewRevealWidth : _rearViewRevealWidth; + if ( xWidth < 0 ) xWidth = _contentView.bounds.size.width + xWidth; + + *progress = *xLocation/xWidth * symetry; } - (void)_getDragLocation:(CGFloat*)xLocation progress:(CGFloat*)progress overdrawProgress:(CGFloat*)overProgress { - UIView *frontView = _contentView.frontView; - *xLocation = frontView.frame.origin.x; - - int symetry = *xLocation<0 ? -1 : 1; - - CGFloat xWidth = symetry < 0 ? _rightViewRevealWidth : _rearViewRevealWidth; - CGFloat xOverWidth = symetry < 0 ? _rightViewRevealOverdraw : _rearViewRevealOverdraw; - - if ( xWidth < 0 ) xWidth = _contentView.bounds.size.width + xWidth; - - *progress = *xLocation*symetry/xWidth; - *overProgress = (*xLocation*symetry-xWidth)/xOverWidth; + UIView *frontView = _contentView.frontView; + *xLocation = frontView.frame.origin.x; + + int symetry = *xLocation<0 ? -1 : 1; + + CGFloat xWidth = symetry < 0 ? _rightViewRevealWidth : _rearViewRevealWidth; + CGFloat xOverWidth = symetry < 0 ? _rightViewRevealOverdraw : _rearViewRevealOverdraw; + + if ( xWidth < 0 ) xWidth = _contentView.bounds.size.width + xWidth; + + *progress = *xLocation*symetry/xWidth; + *overProgress = (*xLocation*symetry-xWidth)/xOverWidth; } @@ -1079,25 +1084,25 @@ - (void)_getDragLocation:(CGFloat*)xLocation progress:(CGFloat*)progress overdra // or executes the block right away if no pending requests are present. - (void)_enqueueBlock:(void (^)(void))block { - [_animationQueue insertObject:block atIndex:0]; - if ( _animationQueue.count == 1) - { - block(); - } + [_animationQueue insertObject:block atIndex:0]; + if ( _animationQueue.count == 1) + { + block(); + } } // Removes the top most block in the queue and executes the following one if any. // Calls to this method must be paired with calls to _enqueueBlock, particularly it may be called -// from within a block passed to _enqueueBlock to remove itself when done with animations. +// from within a block passed to _enqueueBlock to remove itself when done with animations. - (void)_dequeue { - [_animationQueue removeLastObject]; - - if ( _animationQueue.count > 0 ) - { - void (^block)(void) = [_animationQueue lastObject]; - block(); - } + [_animationQueue removeLastObject]; + + if ( _animationQueue.count > 0 ) + { + void (^block)(void) = [_animationQueue lastObject]; + block(); + } } @@ -1105,83 +1110,83 @@ - (void)_dequeue - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)recognizer { - // only allow gesture if no previous request is in process - if ( _animationQueue.count == 0 ) - { - if ( recognizer == _panGestureRecognizer ) - return [self _panGestureShouldBegin]; - - if ( recognizer == _tapGestureRecognizer ) - return [self _tapGestureShouldBegin]; - } - - return NO; + // only allow gesture if no previous request is in process + if ( _animationQueue.count == 0 ) + { + if ( recognizer == _panGestureRecognizer ) + return [self _panGestureShouldBegin]; + + if ( recognizer == _tapGestureRecognizer ) + return [self _tapGestureShouldBegin]; + } + + return NO; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { - if ( gestureRecognizer == _panGestureRecognizer ) - { - if ( [_delegate respondsToSelector:@selector(revealController:panGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:)] ) - if ( [_delegate revealController:self panGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer] != NO ) - return YES; - } - if ( gestureRecognizer == _tapGestureRecognizer ) - { - if ( [_delegate respondsToSelector:@selector(revealController:tapGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:)] ) - if ( [_delegate revealController:self tapGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer] != NO ) - return YES; - } - - return NO; + if ( gestureRecognizer == _panGestureRecognizer ) + { + if ( [_delegate respondsToSelector:@selector(revealController:panGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:)] ) + if ( [_delegate revealController:self panGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer] != NO ) + return YES; + } + if ( gestureRecognizer == _tapGestureRecognizer ) + { + if ( [_delegate respondsToSelector:@selector(revealController:tapGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:)] ) + if ( [_delegate revealController:self tapGestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer] != NO ) + return YES; + } + + return NO; } - (BOOL)_tapGestureShouldBegin { - if ( _frontViewPosition == FrontViewPositionLeft || - _frontViewPosition == FrontViewPositionRightMostRemoved || - _frontViewPosition == FrontViewPositionLeftSideMostRemoved ) - return NO; - - // forbid gesture if the following delegate is implemented and returns NO - if ( [_delegate respondsToSelector:@selector(revealControllerTapGestureShouldBegin:)] ) - if ( [_delegate revealControllerTapGestureShouldBegin:self] == NO ) - return NO; - - return YES; + if ( _frontViewPosition == FrontViewPositionLeft || + _frontViewPosition == FrontViewPositionRightMostRemoved || + _frontViewPosition == FrontViewPositionLeftSideMostRemoved ) + return NO; + + // forbid gesture if the following delegate is implemented and returns NO + if ( [_delegate respondsToSelector:@selector(revealControllerTapGestureShouldBegin:)] ) + if ( [_delegate revealControllerTapGestureShouldBegin:self] == NO ) + return NO; + + return YES; } - (BOOL)_panGestureShouldBegin { - // forbid gesture if the initial translation is not horizontal - UIView *recognizerView = _panGestureRecognizer.view; - CGPoint translation = [_panGestureRecognizer translationInView:recognizerView]; -// NSLog( @"translation:%@", NSStringFromCGPoint(translation) ); -// if ( fabs(translation.y/translation.x) > 1 ) -// return NO; - - // forbid gesture if the following delegate is implemented and returns NO - if ( [_delegate respondsToSelector:@selector(revealControllerPanGestureShouldBegin:)] ) - if ( [_delegate revealControllerPanGestureShouldBegin:self] == NO ) - return NO; - - CGFloat xLocation = [_panGestureRecognizer locationInView:recognizerView].x; - CGFloat width = recognizerView.bounds.size.width; - - BOOL draggableBorderAllowing = ( - /*_frontViewPosition != FrontViewPositionLeft ||*/ _draggableBorderWidth == 0.0f || - (_rearViewController && xLocation <= _draggableBorderWidth) || - (_rightViewController && xLocation >= (width - _draggableBorderWidth)) ); - - - BOOL translationForbidding = ( _frontViewPosition == FrontViewPositionLeft && - ((_rearViewController == nil && translation.x > 0) || (_rightViewController == nil && translation.x < 0)) ); - - // allow gesture only within the bounds defined by the draggableBorderWidth property - return draggableBorderAllowing && !translationForbidding ; + // forbid gesture if the initial translation is not horizontal + UIView *recognizerView = _panGestureRecognizer.view; + CGPoint translation = [_panGestureRecognizer translationInView:recognizerView]; + // NSLog( @"translation:%@", NSStringFromCGPoint(translation) ); + // if ( fabs(translation.y/translation.x) > 1 ) + // return NO; + + // forbid gesture if the following delegate is implemented and returns NO + if ( [_delegate respondsToSelector:@selector(revealControllerPanGestureShouldBegin:)] ) + if ( [_delegate revealControllerPanGestureShouldBegin:self] == NO ) + return NO; + + CGFloat xLocation = [_panGestureRecognizer locationInView:recognizerView].x; + CGFloat width = recognizerView.bounds.size.width; + + BOOL draggableBorderAllowing = ( + /*_frontViewPosition != FrontViewPositionLeft ||*/ _draggableBorderWidth == 0.0f || + (_rearViewController && xLocation <= _draggableBorderWidth) || + (_rightViewController && xLocation >= (width - _draggableBorderWidth)) ); + + + BOOL translationForbidding = ( _frontViewPosition == FrontViewPositionLeft && + ((_rearViewController == nil && translation.x > 0) || (_rightViewController == nil && translation.x < 0)) ); + + // allow gesture only within the bounds defined by the draggableBorderWidth property + return draggableBorderAllowing && !translationForbidding ; } @@ -1189,164 +1194,164 @@ - (BOOL)_panGestureShouldBegin - (void)_handleTapGesture:(UITapGestureRecognizer *)recognizer { - NSTimeInterval duration = _toggleAnimationDuration; - [self _setFrontViewPosition:FrontViewPositionLeft withDuration:duration]; + NSTimeInterval duration = _toggleAnimationDuration; + [self _setFrontViewPosition:FrontViewPositionLeft withDuration:duration]; } - (void)_handleRevealGesture:(UIPanGestureRecognizer *)recognizer { - switch ( recognizer.state ) - { - case UIGestureRecognizerStateBegan: - [self _handleRevealGestureStateBeganWithRecognizer:recognizer]; - break; - - case UIGestureRecognizerStateChanged: - [self _handleRevealGestureStateChangedWithRecognizer:recognizer]; - break; - - case UIGestureRecognizerStateEnded: - [self _handleRevealGestureStateEndedWithRecognizer:recognizer]; - break; - - case UIGestureRecognizerStateCancelled: - //case UIGestureRecognizerStateFailed: - [self _handleRevealGestureStateCancelledWithRecognizer:recognizer]; - break; - - default: - break; - } + switch ( recognizer.state ) + { + case UIGestureRecognizerStateBegan: + [self _handleRevealGestureStateBeganWithRecognizer:recognizer]; + break; + + case UIGestureRecognizerStateChanged: + [self _handleRevealGestureStateChangedWithRecognizer:recognizer]; + break; + + case UIGestureRecognizerStateEnded: + [self _handleRevealGestureStateEndedWithRecognizer:recognizer]; + break; + + case UIGestureRecognizerStateCancelled: + //case UIGestureRecognizerStateFailed: + [self _handleRevealGestureStateCancelledWithRecognizer:recognizer]; + break; + + default: + break; + } } - (void)_handleRevealGestureStateBeganWithRecognizer:(UIPanGestureRecognizer *)recognizer { - // we know that we will not get here unless the animationQueue is empty because the recognizer - // delegate prevents it, however we do not want any forthcoming programatic actions to disturb - // the gesture, so we just enqueue a dummy block to ensure any programatic acctions will be - // scheduled after the gesture is completed - [self _enqueueBlock:^{}]; // <-- dummy block - - // we store the initial position and initialize a target position - _panInitialFrontPosition = _frontViewPosition; - - // we disable user interactions on the views, however programatic accions will still be - // enqueued to be performed after the gesture completes - [self _disableUserInteraction]; - [self _notifyPanGestureBegan]; + // we know that we will not get here unless the animationQueue is empty because the recognizer + // delegate prevents it, however we do not want any forthcoming programatic actions to disturb + // the gesture, so we just enqueue a dummy block to ensure any programatic acctions will be + // scheduled after the gesture is completed + [self _enqueueBlock:^{}]; // <-- dummy block + + // we store the initial position and initialize a target position + _panInitialFrontPosition = _frontViewPosition; + + // we disable user interactions on the views, however programatic accions will still be + // enqueued to be performed after the gesture completes + [self _disableUserInteraction]; + [self _notifyPanGestureBegan]; } - (void)_handleRevealGestureStateChangedWithRecognizer:(UIPanGestureRecognizer *)recognizer { - CGFloat translation = [recognizer translationInView:_contentView].x; - - CGFloat baseLocation = [_contentView frontLocationForPosition:_panInitialFrontPosition]; - CGFloat xLocation = baseLocation + translation; - - if ( xLocation < 0 ) - { - if ( _rightViewController == nil ) xLocation = 0; - [self _rightViewDeploymentForNewFrontViewPosition:FrontViewPositionLeftSide](); - [self _rearViewDeploymentForNewFrontViewPosition:FrontViewPositionLeftSide](); - } - - if ( xLocation > 0 ) - { - if ( _rearViewController == nil ) xLocation = 0; - [self _rightViewDeploymentForNewFrontViewPosition:FrontViewPositionRight](); - [self _rearViewDeploymentForNewFrontViewPosition:FrontViewPositionRight](); - } - - [_contentView dragFrontViewToXLocation:xLocation]; - [self _notifyPanGestureMoved]; + CGFloat translation = [recognizer translationInView:_contentView].x; + + CGFloat baseLocation = [_contentView frontLocationForPosition:_panInitialFrontPosition]; + CGFloat xLocation = baseLocation + translation; + + if ( xLocation < 0 ) + { + if ( _rightViewController == nil ) xLocation = 0; + [self _rightViewDeploymentForNewFrontViewPosition:FrontViewPositionLeftSide](); + [self _rearViewDeploymentForNewFrontViewPosition:FrontViewPositionLeftSide](); + } + + if ( xLocation > 0 ) + { + if ( _rearViewController == nil ) xLocation = 0; + [self _rightViewDeploymentForNewFrontViewPosition:FrontViewPositionRight](); + [self _rearViewDeploymentForNewFrontViewPosition:FrontViewPositionRight](); + } + + [_contentView dragFrontViewToXLocation:xLocation]; + [self _notifyPanGestureMoved]; } - (void)_handleRevealGestureStateEndedWithRecognizer:(UIPanGestureRecognizer *)recognizer { - UIView *frontView = _contentView.frontView; - - CGFloat xLocation = frontView.frame.origin.x; - CGFloat velocity = [recognizer velocityInView:_contentView].x; - //NSLog( @"Velocity:%1.4f", velocity); - - // depending on position we compute a simetric replacement of widths and positions - int symetry = xLocation<0 ? -1 : 1; - - // simetring computing of widths - CGFloat revealWidth ; - CGFloat revealOverdraw ; - BOOL bounceBack; - BOOL stableDrag; - - [self _getRevealWidth:&revealWidth revealOverDraw:&revealOverdraw forSymetry:symetry]; - [self _getBounceBack:&bounceBack pStableDrag:&stableDrag forSymetry:symetry]; - - // simetric replacement of position - xLocation = xLocation * symetry; - - // initially we assume drag to left and default duration - FrontViewPosition frontViewPosition = FrontViewPositionLeft; - NSTimeInterval duration = _toggleAnimationDuration; - - // Velocity driven change: - if (ABS(velocity) > _quickFlickVelocity) - { - // we may need to set the drag position and to adjust the animation duration - CGFloat journey = xLocation; - if (velocity*symetry > 0.0f) - { - frontViewPosition = FrontViewPositionRight; - journey = revealWidth - xLocation; - if (xLocation > revealWidth) - { - if (!bounceBack && stableDrag /*&& xPosition > _rearViewRevealWidth+_rearViewRevealOverdraw*0.5f*/) - { - frontViewPosition = FrontViewPositionRightMost; - journey = revealWidth+revealOverdraw - xLocation; - } - } - } - - duration = ABS(journey/velocity); - } - - // Position driven change: - else - { - // we may need to set the drag position - if (xLocation > revealWidth*0.5f) - { - frontViewPosition = FrontViewPositionRight; - if (xLocation > revealWidth) - { - if (bounceBack) - frontViewPosition = FrontViewPositionLeft; - - else if (stableDrag && xLocation > revealWidth+revealOverdraw*0.5f) - frontViewPosition = FrontViewPositionRightMost; - } - } - } - - // symetric replacement of frontViewPosition - [self _getAdjustedFrontViewPosition:&frontViewPosition forSymetry:symetry]; - - // restore user interaction and animate to the final position - [self _restoreUserInteraction]; - [self _notifyPanGestureEnded]; - [self _setFrontViewPosition:frontViewPosition withDuration:duration]; + UIView *frontView = _contentView.frontView; + + CGFloat xLocation = frontView.frame.origin.x; + CGFloat velocity = [recognizer velocityInView:_contentView].x; + //NSLog( @"Velocity:%1.4f", velocity); + + // depending on position we compute a simetric replacement of widths and positions + int symetry = xLocation<0 ? -1 : 1; + + // simetring computing of widths + CGFloat revealWidth ; + CGFloat revealOverdraw ; + BOOL bounceBack; + BOOL stableDrag; + + [self _getRevealWidth:&revealWidth revealOverDraw:&revealOverdraw forSymetry:symetry]; + [self _getBounceBack:&bounceBack pStableDrag:&stableDrag forSymetry:symetry]; + + // simetric replacement of position + xLocation = xLocation * symetry; + + // initially we assume drag to left and default duration + FrontViewPosition frontViewPosition = FrontViewPositionLeft; + NSTimeInterval duration = _toggleAnimationDuration; + + // Velocity driven change: + if (ABS(velocity) > _quickFlickVelocity) + { + // we may need to set the drag position and to adjust the animation duration + CGFloat journey = xLocation; + if (velocity*symetry > 0.0f) + { + frontViewPosition = FrontViewPositionRight; + journey = revealWidth - xLocation; + if (xLocation > revealWidth) + { + if (!bounceBack && stableDrag /*&& xPosition > _rearViewRevealWidth+_rearViewRevealOverdraw*0.5f*/) + { + frontViewPosition = FrontViewPositionRightMost; + journey = revealWidth+revealOverdraw - xLocation; + } + } + } + + duration = ABS(journey/velocity); + } + + // Position driven change: + else + { + // we may need to set the drag position + if (xLocation > revealWidth*0.5f) + { + frontViewPosition = FrontViewPositionRight; + if (xLocation > revealWidth) + { + if (bounceBack) + frontViewPosition = FrontViewPositionLeft; + + else if (stableDrag && xLocation > revealWidth+revealOverdraw*0.5f) + frontViewPosition = FrontViewPositionRightMost; + } + } + } + + // symetric replacement of frontViewPosition + [self _getAdjustedFrontViewPosition:&frontViewPosition forSymetry:symetry]; + + // restore user interaction and animate to the final position + [self _restoreUserInteraction]; + [self _notifyPanGestureEnded]; + [self _setFrontViewPosition:frontViewPosition withDuration:duration]; } - (void)_handleRevealGestureStateCancelledWithRecognizer:(UIPanGestureRecognizer *)recognizer -{ - [self _restoreUserInteraction]; - [self _notifyPanGestureEnded]; - [self _dequeue]; +{ + [self _restoreUserInteraction]; + [self _notifyPanGestureEnded]; + [self _dequeue]; } @@ -1354,42 +1359,42 @@ - (void)_handleRevealGestureStateCancelledWithRecognizer:(UIPanGestureRecognizer - (void)_dispatchSetFrontViewPosition:(FrontViewPosition)frontViewPosition animated:(BOOL)animated { - NSTimeInterval duration = animated?_toggleAnimationDuration:0.0; - __weak SWRevealViewController *theSelf = self; - _enqueue( [theSelf _setFrontViewPosition:frontViewPosition withDuration:duration] ); + NSTimeInterval duration = animated?_toggleAnimationDuration:0.0; + __weak SWRevealViewController *theSelf = self; + _enqueue( [theSelf _setFrontViewPosition:frontViewPosition withDuration:duration] ); } - (void)_dispatchPushFrontViewController:(UIViewController *)newFrontViewController animated:(BOOL)animated { - FrontViewPosition preReplacementPosition = FrontViewPositionLeft; - if ( _frontViewPosition > FrontViewPositionLeft ) preReplacementPosition = FrontViewPositionRightMost; - if ( _frontViewPosition < FrontViewPositionLeft ) preReplacementPosition = FrontViewPositionLeftSideMost; - - NSTimeInterval duration = animated?_toggleAnimationDuration:0.0; - NSTimeInterval firstDuration = duration; - NSInteger initialPosDif = ABS( _frontViewPosition - preReplacementPosition ); - if ( initialPosDif == 1 ) firstDuration *= 0.8; - else if ( initialPosDif == 0 ) firstDuration = 0; - - __weak SWRevealViewController *theSelf = self; - if ( animated ) - { - _enqueue( [theSelf _setFrontViewPosition:preReplacementPosition withDuration:firstDuration] ); - _enqueue( [theSelf _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:newFrontViewController animated:NO] ); - _enqueue( [theSelf _setFrontViewPosition:FrontViewPositionLeft withDuration:duration] ); - } - else - { - _enqueue( [theSelf _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:newFrontViewController animated:NO] ); - } + FrontViewPosition preReplacementPosition = FrontViewPositionLeft; + if ( _frontViewPosition > FrontViewPositionLeft ) preReplacementPosition = FrontViewPositionRightMost; + if ( _frontViewPosition < FrontViewPositionLeft ) preReplacementPosition = FrontViewPositionLeftSideMost; + + NSTimeInterval duration = animated?_toggleAnimationDuration:0.0; + NSTimeInterval firstDuration = duration; + NSInteger initialPosDif = ABS( _frontViewPosition - preReplacementPosition ); + if ( initialPosDif == 1 ) firstDuration *= 0.8; + else if ( initialPosDif == 0 ) firstDuration = 0; + + __weak SWRevealViewController *theSelf = self; + if ( animated ) + { + _enqueue( [theSelf _setFrontViewPosition:preReplacementPosition withDuration:firstDuration] ); + _enqueue( [theSelf _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:newFrontViewController animated:NO] ); + _enqueue( [theSelf _setFrontViewPosition:FrontViewPositionLeft withDuration:duration] ); + } + else + { + _enqueue( [theSelf _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:newFrontViewController animated:NO] ); + } } - (void)_dispatchTransitionOperation:(SWRevealControllerOperation)operation withViewController:(UIViewController *)newViewController animated:(BOOL)animated { - __weak SWRevealViewController *theSelf = self; - _enqueue( [theSelf _performTransitionOperation:operation withViewController:newViewController animated:animated] ); + __weak SWRevealViewController *theSelf = self; + _enqueue( [theSelf _performTransitionOperation:operation withViewController:newViewController animated:animated] ); } @@ -1398,49 +1403,49 @@ - (void)_dispatchTransitionOperation:(SWRevealControllerOperation)operation with // Primitive method for view controller deployment and animated layout to the given position. - (void)_setFrontViewPosition:(FrontViewPosition)newPosition withDuration:(NSTimeInterval)duration { - void (^rearDeploymentCompletion)() = [self _rearViewDeploymentForNewFrontViewPosition:newPosition]; - void (^rightDeploymentCompletion)() = [self _rightViewDeploymentForNewFrontViewPosition:newPosition]; - void (^frontDeploymentCompletion)() = [self _frontViewDeploymentForNewFrontViewPosition:newPosition]; - - void (^animations)() = ^() - { - // Calling this in the animation block causes the status bar to appear/dissapear in sync with our own animation - [self setNeedsStatusBarAppearanceUpdate]; - - // We call the layoutSubviews method on the contentView view and send a delegate, which will - // occur inside of an animation block if any animated transition is being performed - [_contentView layoutSubviews]; - - if ([_delegate respondsToSelector:@selector(revealController:animateToPosition:)]) - [_delegate revealController:self animateToPosition:_frontViewPosition]; - }; - - void (^completion)(BOOL) = ^(BOOL finished) - { - rearDeploymentCompletion(); - rightDeploymentCompletion(); - frontDeploymentCompletion(); - [self _dequeue]; - }; - - if ( duration > 0.0 ) - { - if ( _toggleAnimationType == SWRevealToggleAnimationTypeEaseOut ) - { - [UIView animateWithDuration:duration delay:0.0 - options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion]; - } - else - { - [UIView animateWithDuration:_toggleAnimationDuration delay:0.0 usingSpringWithDamping:_springDampingRatio initialSpringVelocity:1/duration - options:0 animations:animations completion:completion]; - } - } - else - { - animations(); - completion(YES); - } + void (^rearDeploymentCompletion)(void) = [self _rearViewDeploymentForNewFrontViewPosition:newPosition]; + void (^rightDeploymentCompletion)(void) = [self _rightViewDeploymentForNewFrontViewPosition:newPosition]; + void (^frontDeploymentCompletion)(void) = [self _frontViewDeploymentForNewFrontViewPosition:newPosition]; + + void (^animations)(void) = ^() + { + // Calling this in the animation block causes the status bar to appear/dissapear in sync with our own animation + [self setNeedsStatusBarAppearanceUpdate]; + + // We call the layoutSubviews method on the contentView view and send a delegate, which will + // occur inside of an animation block if any animated transition is being performed + [self->_contentView layoutSubviews]; + + if ([self->_delegate respondsToSelector:@selector(revealController:animateToPosition:)]) + [self->_delegate revealController:self animateToPosition:self->_frontViewPosition]; + }; + + void (^completion)(BOOL) = ^(BOOL finished) + { + rearDeploymentCompletion(); + rightDeploymentCompletion(); + frontDeploymentCompletion(); + [self _dequeue]; + }; + + if ( duration > 0.0 ) + { + if ( _toggleAnimationType == SWRevealToggleAnimationTypeEaseOut ) + { + [UIView animateWithDuration:duration delay:0.0 + options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion]; + } + else + { + [UIView animateWithDuration:_toggleAnimationDuration delay:0.0 usingSpringWithDamping:_springDampingRatio initialSpringVelocity:1/duration + options:0 animations:animations completion:completion]; + } + } + else + { + animations(); + completion(YES); + } } @@ -1448,54 +1453,54 @@ - (void)_setFrontViewPosition:(FrontViewPosition)newPosition withDuration:(NSTim //- (void)_performTransitionToViewController:(UIViewController*)new operation:(SWRevealControllerOperation)operation animated:(BOOL)animated - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withViewController:(UIViewController*)new animated:(BOOL)animated { - if ( [_delegate respondsToSelector:@selector(revealController:willAddViewController:forOperation:animated:)] ) - [_delegate revealController:self willAddViewController:new forOperation:operation animated:animated]; - - UIViewController *old = nil; - UIView *view = nil; - - if ( operation == SWRevealControllerOperationReplaceRearController ) - old = _rearViewController, _rearViewController = new, view = _contentView.rearView; - - else if ( operation == SWRevealControllerOperationReplaceFrontController ) - old = _frontViewController, _frontViewController = new, view = _contentView.frontView; - - else if ( operation == SWRevealControllerOperationReplaceRightController ) - old = _rightViewController, _rightViewController = new, view = _contentView.rightView; - - void (^completion)() = [self _transitionFromViewController:old toViewController:new inView:view]; - - void (^animationCompletion)() = ^ - { - completion(); - if ( [_delegate respondsToSelector:@selector(revealController:didAddViewController:forOperation:animated:)] ) - [_delegate revealController:self didAddViewController:new forOperation:operation animated:animated]; - - [self _dequeue]; - }; - - if ( animated ) - { - id animationController = nil; - - if ( [_delegate respondsToSelector:@selector(revealController:animationControllerForOperation:fromViewController:toViewController:)] ) - animationController = [_delegate revealController:self animationControllerForOperation:operation fromViewController:old toViewController:new]; - - if ( !animationController ) - animationController = [[SWDefaultAnimationController alloc] initWithDuration:_replaceViewAnimationDuration]; - - SWContextTransitionObject *transitioningObject = [[SWContextTransitionObject alloc] initWithRevealController:self containerView:view - fromVC:old toVC:new completion:animationCompletion]; - - if ( [animationController transitionDuration:transitioningObject] > 0 ) - [animationController animateTransition:transitioningObject]; - else - animationCompletion(); - } - else - { - animationCompletion(); - } + if ( [_delegate respondsToSelector:@selector(revealController:willAddViewController:forOperation:animated:)] ) + [_delegate revealController:self willAddViewController:new forOperation:operation animated:animated]; + + UIViewController *old = nil; + UIView *view = nil; + + if ( operation == SWRevealControllerOperationReplaceRearController ) + (void)(old = _rearViewController), (void)(_rearViewController = new), view = _contentView.rearView; + + else if ( operation == SWRevealControllerOperationReplaceFrontController ) + (void)(old = _frontViewController), (void)(_frontViewController = new), view = _contentView.frontView; + + else if ( operation == SWRevealControllerOperationReplaceRightController ) + (void)(old = _rightViewController), (void)(_rightViewController = new), view = _contentView.rightView; + + void (^completion)(void) = [self _transitionFromViewController:old toViewController:new inView:view]; + + void (^animationCompletion)(void) = ^ + { + completion(); + if ( [self->_delegate respondsToSelector:@selector(revealController:didAddViewController:forOperation:animated:)] ) + [self->_delegate revealController:self didAddViewController:new forOperation:operation animated:animated]; + + [self _dequeue]; + }; + + if ( animated ) + { + id animationController = nil; + + if ( [_delegate respondsToSelector:@selector(revealController:animationControllerForOperation:fromViewController:toViewController:)] ) + animationController = [_delegate revealController:self animationControllerForOperation:operation fromViewController:old toViewController:new]; + + if ( !animationController ) + animationController = [[SWDefaultAnimationController alloc] initWithDuration:_replaceViewAnimationDuration]; + + SWContextTransitionObject *transitioningObject = [[SWContextTransitionObject alloc] initWithRevealController:self containerView:view + fromVC:old toVC:new completion:animationCompletion]; + + if ( [animationController transitionDuration:transitioningObject] > 0 ) + [animationController animateTransition:transitioningObject]; + else + animationCompletion(); + } + else + { + animationCompletion(); + } } @@ -1505,109 +1510,109 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV // that must be invoked on animation completion in order to finish deployment - (void (^)(void))_frontViewDeploymentForNewFrontViewPosition:(FrontViewPosition)newPosition { - if ( (_rightViewController == nil && newPosition < FrontViewPositionLeft) || - (_rearViewController == nil && newPosition > FrontViewPositionLeft) ) - newPosition = FrontViewPositionLeft; - - BOOL positionIsChanging = (_frontViewPosition != newPosition); - - BOOL appear = - (_frontViewPosition >= FrontViewPositionRightMostRemoved || _frontViewPosition <= FrontViewPositionLeftSideMostRemoved || _frontViewPosition == FrontViewPositionNone) && - (newPosition < FrontViewPositionRightMostRemoved && newPosition > FrontViewPositionLeftSideMostRemoved); - - BOOL disappear = - (newPosition >= FrontViewPositionRightMostRemoved || newPosition <= FrontViewPositionLeftSideMostRemoved ) && - (_frontViewPosition < FrontViewPositionRightMostRemoved && _frontViewPosition > FrontViewPositionLeftSideMostRemoved && _frontViewPosition != FrontViewPositionNone); - - if ( positionIsChanging ) - { - if ( [_delegate respondsToSelector:@selector(revealController:willMoveToPosition:)] ) - [_delegate revealController:self willMoveToPosition:newPosition]; - } - - _frontViewPosition = newPosition; - - void (^deploymentCompletion)() = - [self _deploymentForViewController:_frontViewController inView:_contentView.frontView appear:appear disappear:disappear]; - - void (^completion)() = ^() - { - deploymentCompletion(); - if ( positionIsChanging ) - { - if ( [_delegate respondsToSelector:@selector(revealController:didMoveToPosition:)] ) - [_delegate revealController:self didMoveToPosition:newPosition]; - } - }; - - return completion; + if ( (_rightViewController == nil && newPosition < FrontViewPositionLeft) || + (_rearViewController == nil && newPosition > FrontViewPositionLeft) ) + newPosition = FrontViewPositionLeft; + + BOOL positionIsChanging = (_frontViewPosition != newPosition); + + BOOL appear = + (_frontViewPosition >= FrontViewPositionRightMostRemoved || _frontViewPosition <= FrontViewPositionLeftSideMostRemoved || _frontViewPosition == FrontViewPositionNone) && + (newPosition < FrontViewPositionRightMostRemoved && newPosition > FrontViewPositionLeftSideMostRemoved); + + BOOL disappear = + (newPosition >= FrontViewPositionRightMostRemoved || newPosition <= FrontViewPositionLeftSideMostRemoved ) && + (_frontViewPosition < FrontViewPositionRightMostRemoved && _frontViewPosition > FrontViewPositionLeftSideMostRemoved && _frontViewPosition != FrontViewPositionNone); + + if ( positionIsChanging ) + { + if ( [_delegate respondsToSelector:@selector(revealController:willMoveToPosition:)] ) + [_delegate revealController:self willMoveToPosition:newPosition]; + } + + _frontViewPosition = newPosition; + + void (^deploymentCompletion)(void) = + [self _deploymentForViewController:_frontViewController inView:_contentView.frontView appear:appear disappear:disappear]; + + void (^completion)(void) = ^() + { + deploymentCompletion(); + if ( positionIsChanging ) + { + if ( [self->_delegate respondsToSelector:@selector(revealController:didMoveToPosition:)] ) + [self->_delegate revealController:self didMoveToPosition:newPosition]; + } + }; + + return completion; } // Deploy/Undeploy of the left view controller following the containment principles. Returns a block // that must be invoked on animation completion in order to finish deployment - (void (^)(void))_rearViewDeploymentForNewFrontViewPosition:(FrontViewPosition)newPosition { - if ( _presentFrontViewHierarchically ) - newPosition = FrontViewPositionRight; - - if ( _rearViewController == nil && newPosition > FrontViewPositionLeft ) - newPosition = FrontViewPositionLeft; - - BOOL appear = (_rearViewPosition <= FrontViewPositionLeft || _rearViewPosition == FrontViewPositionNone) && newPosition > FrontViewPositionLeft; - BOOL disappear = newPosition <= FrontViewPositionLeft && (_rearViewPosition > FrontViewPositionLeft && _rearViewPosition != FrontViewPositionNone); - - if ( appear ) - [_contentView prepareRearViewForPosition:newPosition]; - - _rearViewPosition = newPosition; - - void (^deploymentCompletion)() = - [self _deploymentForViewController:_rearViewController inView:_contentView.rearView appear:appear disappear:disappear]; - - void (^completion)() = ^() - { - deploymentCompletion(); - if ( disappear ) - [_contentView unloadRearView]; - }; - - return completion; + if ( _presentFrontViewHierarchically ) + newPosition = FrontViewPositionRight; + + if ( _rearViewController == nil && newPosition > FrontViewPositionLeft ) + newPosition = FrontViewPositionLeft; + + BOOL appear = (_rearViewPosition <= FrontViewPositionLeft || _rearViewPosition == FrontViewPositionNone) && newPosition > FrontViewPositionLeft; + BOOL disappear = newPosition <= FrontViewPositionLeft && (_rearViewPosition > FrontViewPositionLeft && _rearViewPosition != FrontViewPositionNone); + + if ( appear ) + [_contentView prepareRearViewForPosition:newPosition]; + + _rearViewPosition = newPosition; + + void (^deploymentCompletion)(void) = + [self _deploymentForViewController:_rearViewController inView:_contentView.rearView appear:appear disappear:disappear]; + + void (^completion)(void) = ^() + { + deploymentCompletion(); + if ( disappear ) + [self->_contentView unloadRearView]; + }; + + return completion; } // Deploy/Undeploy of the right view controller following the containment principles. Returns a block // that must be invoked on animation completion in order to finish deployment - (void (^)(void))_rightViewDeploymentForNewFrontViewPosition:(FrontViewPosition)newPosition { - if ( _rightViewController == nil && newPosition < FrontViewPositionLeft ) - newPosition = FrontViewPositionLeft; - - BOOL appear = (_rightViewPosition >= FrontViewPositionLeft || _rightViewPosition == FrontViewPositionNone) && newPosition < FrontViewPositionLeft ; - BOOL disappear = newPosition >= FrontViewPositionLeft && (_rightViewPosition < FrontViewPositionLeft && _rightViewPosition != FrontViewPositionNone); - - if ( appear ) - [_contentView prepareRightViewForPosition:newPosition]; - - _rightViewPosition = newPosition; - - void (^deploymentCompletion)() = - [self _deploymentForViewController:_rightViewController inView:_contentView.rightView appear:appear disappear:disappear]; - - void (^completion)() = ^() - { - deploymentCompletion(); - if ( disappear ) - [_contentView unloadRightView]; - }; - - return completion; + if ( _rightViewController == nil && newPosition < FrontViewPositionLeft ) + newPosition = FrontViewPositionLeft; + + BOOL appear = (_rightViewPosition >= FrontViewPositionLeft || _rightViewPosition == FrontViewPositionNone) && newPosition < FrontViewPositionLeft ; + BOOL disappear = newPosition >= FrontViewPositionLeft && (_rightViewPosition < FrontViewPositionLeft && _rightViewPosition != FrontViewPositionNone); + + if ( appear ) + [_contentView prepareRightViewForPosition:newPosition]; + + _rightViewPosition = newPosition; + + void (^deploymentCompletion)(void) = + [self _deploymentForViewController:_rightViewController inView:_contentView.rightView appear:appear disappear:disappear]; + + void (^completion)(void) = ^() + { + deploymentCompletion(); + if ( disappear ) + [self->_contentView unloadRightView]; + }; + + return completion; } - (void (^)(void)) _deploymentForViewController:(UIViewController*)controller inView:(UIView*)view appear:(BOOL)appear disappear:(BOOL)disappear { - if ( appear ) return [self _deployForViewController:controller inView:view]; - if ( disappear ) return [self _undeployForViewController:controller]; - return ^{}; + if ( appear ) return [self _deployForViewController:controller inView:view]; + if ( disappear ) return [self _undeployForViewController:controller]; + return ^{}; } @@ -1617,103 +1622,103 @@ - (void)_performTransitionOperation:(SWRevealControllerOperation)operation withV // animation completion, or right after return in case of non-animated deployment. - (void (^)(void))_deployForViewController:(UIViewController*)controller inView:(UIView*)view { - if ( !controller || !view ) - return ^(void){}; - - CGRect frame = view.bounds; - - UIView *controllerView = controller.view; - controllerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - controllerView.frame = frame; - - if ( [controllerView isKindOfClass:[UIScrollView class]] ) - { - BOOL adjust = controller.automaticallyAdjustsScrollViewInsets; - - if ( adjust ) - { - [(id)controllerView setContentInset:UIEdgeInsetsMake(statusBarAdjustment(_contentView), 0, 0, 0)]; - } - } - - [view addSubview:controllerView]; - - void (^completionBlock)(void) = ^(void) - { - // nothing to do on completion at this stage - }; - - return completionBlock; + if ( !controller || !view ) + return ^(void){}; + + CGRect frame = view.bounds; + + UIView *controllerView = controller.view; + controllerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + controllerView.frame = frame; + + if ( [controllerView isKindOfClass:[UIScrollView class]] ) + { + BOOL adjust = controller.automaticallyAdjustsScrollViewInsets; + + if ( adjust ) + { + [(id)controllerView setContentInset:UIEdgeInsetsMake(statusBarAdjustment(_contentView), 0, 0, 0)]; + } + } + + [view addSubview:controllerView]; + + void (^completionBlock)(void) = ^(void) + { + // nothing to do on completion at this stage + }; + + return completionBlock; } // Containment Undeploy method. Returns a block to be invoked at the // animation completion, or right after return in case of non-animated deployment. - (void (^)(void))_undeployForViewController:(UIViewController*)controller { - if (!controller) - return ^(void){}; - - // nothing to do before completion at this stage - - void (^completionBlock)(void) = ^(void) - { - [controller.view removeFromSuperview]; - }; - - return completionBlock; + if (!controller) + return ^(void){}; + + // nothing to do before completion at this stage + + void (^completionBlock)(void) = ^(void) + { + [controller.view removeFromSuperview]; + }; + + return completionBlock; } // Containment Transition method. Returns a block to be invoked at the // animation completion, or right after return in case of non-animated transition. - (void(^)(void))_transitionFromViewController:(UIViewController*)fromController toViewController:(UIViewController*)toController inView:(UIView*)view { - if ( fromController == toController ) - return ^(void){}; - - if ( toController ) [self addChildViewController:toController]; - - void (^deployCompletion)() = [self _deployForViewController:toController inView:view]; - - [fromController willMoveToParentViewController:nil]; - - void (^undeployCompletion)() = [self _undeployForViewController:fromController]; - - void (^completionBlock)(void) = ^(void) - { - undeployCompletion() ; - [fromController removeFromParentViewController]; - - deployCompletion() ; - [toController didMoveToParentViewController:self]; - }; - return completionBlock; + if ( fromController == toController ) + return ^(void){}; + + if ( toController ) [self addChildViewController:toController]; + + void (^deployCompletion)(void) = [self _deployForViewController:toController inView:view]; + + [fromController willMoveToParentViewController:nil]; + + void (^undeployCompletion)(void) = [self _undeployForViewController:fromController]; + + void (^completionBlock)(void) = ^(void) + { + undeployCompletion() ; + [fromController removeFromParentViewController]; + + deployCompletion() ; + [toController didMoveToParentViewController:self]; + }; + return completionBlock; } // Load any defined front/rear controllers from the storyboard // This method is intended to be overrided in case the default behavior will not meet your needs - (void)loadStoryboardControllers { - if ( self.storyboard && _rearViewController == nil ) - { - //Try each segue separately so it doesn't break prematurely if either Rear or Right views are not used. - @try - { - [self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil]; - } - @catch(NSException *exception) {} - - @try - { - [self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil]; - } - @catch(NSException *exception) {} - - @try - { - [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil]; - } - @catch(NSException *exception) {} - } + if ( self.storyboard && _rearViewController == nil ) + { + //Try each segue separately so it doesn't break prematurely if either Rear or Right views are not used. + @try + { + [self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil]; + } + @catch(NSException *exception) {} + + @try + { + [self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil]; + } + @catch(NSException *exception) {} + + @try + { + [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil]; + } + @catch(NSException *exception) {} + } } @@ -1721,97 +1726,97 @@ - (void)loadStoryboardControllers + (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder*)coder { - SWRevealViewController* vc = nil; - UIStoryboard* sb = [coder decodeObjectForKey:UIStateRestorationViewControllerStoryboardKey]; - - if (sb) - { - vc = (SWRevealViewController*)[sb instantiateViewControllerWithIdentifier:@"SWRevealViewController"]; - vc.restorationIdentifier = [identifierComponents lastObject]; - vc.restorationClass = [SWRevealViewController class]; - } - return vc; + SWRevealViewController* vc = nil; + UIStoryboard* sb = [coder decodeObjectForKey:UIStateRestorationViewControllerStoryboardKey]; + + if (sb) + { + vc = (SWRevealViewController*)[sb instantiateViewControllerWithIdentifier:@"SWRevealViewController"]; + vc.restorationIdentifier = [identifierComponents lastObject]; + vc.restorationClass = [SWRevealViewController class]; + } + return vc; } - (void)encodeRestorableStateWithCoder:(NSCoder *)coder { - [coder encodeDouble:_rearViewRevealWidth forKey:@"_rearViewRevealWidth"]; - [coder encodeDouble:_rearViewRevealOverdraw forKey:@"_rearViewRevealOverdraw"]; - [coder encodeDouble:_rearViewRevealDisplacement forKey:@"_rearViewRevealDisplacement"]; - [coder encodeDouble:_rightViewRevealWidth forKey:@"_rightViewRevealWidth"]; - [coder encodeDouble:_rightViewRevealOverdraw forKey:@"_rightViewRevealOverdraw"]; - [coder encodeDouble:_rightViewRevealDisplacement forKey:@"_rightViewRevealDisplacement"]; - [coder encodeBool:_bounceBackOnOverdraw forKey:@"_bounceBackOnOverdraw"]; - [coder encodeBool:_bounceBackOnLeftOverdraw forKey:@"_bounceBackOnLeftOverdraw"]; - [coder encodeBool:_stableDragOnOverdraw forKey:@"_stableDragOnOverdraw"]; - [coder encodeBool:_stableDragOnLeftOverdraw forKey:@"_stableDragOnLeftOverdraw"]; - [coder encodeBool:_presentFrontViewHierarchically forKey:@"_presentFrontViewHierarchically"]; - [coder encodeDouble:_quickFlickVelocity forKey:@"_quickFlickVelocity"]; - [coder encodeDouble:_toggleAnimationDuration forKey:@"_toggleAnimationDuration"]; - [coder encodeInteger:_toggleAnimationType forKey:@"_toggleAnimationType"]; - [coder encodeDouble:_springDampingRatio forKey:@"_springDampingRatio"]; - [coder encodeDouble:_replaceViewAnimationDuration forKey:@"_replaceViewAnimationDuration"]; - [coder encodeDouble:_frontViewShadowRadius forKey:@"_frontViewShadowRadius"]; - [coder encodeCGSize:_frontViewShadowOffset forKey:@"_frontViewShadowOffset"]; - [coder encodeDouble:_frontViewShadowOpacity forKey:@"_frontViewShadowOpacity"]; - [coder encodeObject:_frontViewShadowColor forKey:@"_frontViewShadowColor"]; - [coder encodeBool:_userInteractionStore forKey:@"_userInteractionStore"]; - [coder encodeDouble:_draggableBorderWidth forKey:@"_draggableBorderWidth"]; - [coder encodeBool:_clipsViewsToBounds forKey:@"_clipsViewsToBounds"]; - [coder encodeBool:_extendsPointInsideHit forKey:@"_extendsPointInsideHit"]; - - [coder encodeObject:_rearViewController forKey:@"_rearViewController"]; - [coder encodeObject:_frontViewController forKey:@"_frontViewController"]; - [coder encodeObject:_rightViewController forKey:@"_rightViewController"]; - - [coder encodeInteger:_frontViewPosition forKey:@"_frontViewPosition"]; - - [super encodeRestorableStateWithCoder:coder]; + [coder encodeDouble:_rearViewRevealWidth forKey:@"_rearViewRevealWidth"]; + [coder encodeDouble:_rearViewRevealOverdraw forKey:@"_rearViewRevealOverdraw"]; + [coder encodeDouble:_rearViewRevealDisplacement forKey:@"_rearViewRevealDisplacement"]; + [coder encodeDouble:_rightViewRevealWidth forKey:@"_rightViewRevealWidth"]; + [coder encodeDouble:_rightViewRevealOverdraw forKey:@"_rightViewRevealOverdraw"]; + [coder encodeDouble:_rightViewRevealDisplacement forKey:@"_rightViewRevealDisplacement"]; + [coder encodeBool:_bounceBackOnOverdraw forKey:@"_bounceBackOnOverdraw"]; + [coder encodeBool:_bounceBackOnLeftOverdraw forKey:@"_bounceBackOnLeftOverdraw"]; + [coder encodeBool:_stableDragOnOverdraw forKey:@"_stableDragOnOverdraw"]; + [coder encodeBool:_stableDragOnLeftOverdraw forKey:@"_stableDragOnLeftOverdraw"]; + [coder encodeBool:_presentFrontViewHierarchically forKey:@"_presentFrontViewHierarchically"]; + [coder encodeDouble:_quickFlickVelocity forKey:@"_quickFlickVelocity"]; + [coder encodeDouble:_toggleAnimationDuration forKey:@"_toggleAnimationDuration"]; + [coder encodeInteger:_toggleAnimationType forKey:@"_toggleAnimationType"]; + [coder encodeDouble:_springDampingRatio forKey:@"_springDampingRatio"]; + [coder encodeDouble:_replaceViewAnimationDuration forKey:@"_replaceViewAnimationDuration"]; + [coder encodeDouble:_frontViewShadowRadius forKey:@"_frontViewShadowRadius"]; + [coder encodeCGSize:_frontViewShadowOffset forKey:@"_frontViewShadowOffset"]; + [coder encodeDouble:_frontViewShadowOpacity forKey:@"_frontViewShadowOpacity"]; + [coder encodeObject:_frontViewShadowColor forKey:@"_frontViewShadowColor"]; + [coder encodeBool:_userInteractionStore forKey:@"_userInteractionStore"]; + [coder encodeDouble:_draggableBorderWidth forKey:@"_draggableBorderWidth"]; + [coder encodeBool:_clipsViewsToBounds forKey:@"_clipsViewsToBounds"]; + [coder encodeBool:_extendsPointInsideHit forKey:@"_extendsPointInsideHit"]; + + [coder encodeObject:_rearViewController forKey:@"_rearViewController"]; + [coder encodeObject:_frontViewController forKey:@"_frontViewController"]; + [coder encodeObject:_rightViewController forKey:@"_rightViewController"]; + + [coder encodeInteger:_frontViewPosition forKey:@"_frontViewPosition"]; + + [super encodeRestorableStateWithCoder:coder]; } - (void)decodeRestorableStateWithCoder:(NSCoder *)coder { - _rearViewRevealWidth = [coder decodeDoubleForKey:@"_rearViewRevealWidth"]; - _rearViewRevealOverdraw = [coder decodeDoubleForKey:@"_rearViewRevealOverdraw"]; - _rearViewRevealDisplacement = [coder decodeDoubleForKey:@"_rearViewRevealDisplacement"]; - _rightViewRevealWidth = [coder decodeDoubleForKey:@"_rightViewRevealWidth"]; - _rightViewRevealOverdraw = [coder decodeDoubleForKey:@"_rightViewRevealOverdraw"]; - _rightViewRevealDisplacement = [coder decodeDoubleForKey:@"_rightViewRevealDisplacement"]; - _bounceBackOnOverdraw = [coder decodeBoolForKey:@"_bounceBackOnOverdraw"]; - _bounceBackOnLeftOverdraw = [coder decodeBoolForKey:@"_bounceBackOnLeftOverdraw"]; - _stableDragOnOverdraw = [coder decodeBoolForKey:@"_stableDragOnOverdraw"]; - _stableDragOnLeftOverdraw = [coder decodeBoolForKey:@"_stableDragOnLeftOverdraw"]; - _presentFrontViewHierarchically = [coder decodeBoolForKey:@"_presentFrontViewHierarchically"]; - _quickFlickVelocity = [coder decodeDoubleForKey:@"_quickFlickVelocity"]; - _toggleAnimationDuration = [coder decodeDoubleForKey:@"_toggleAnimationDuration"]; - _toggleAnimationType = [coder decodeIntegerForKey:@"_toggleAnimationType"]; - _springDampingRatio = [coder decodeDoubleForKey:@"_springDampingRatio"]; - _replaceViewAnimationDuration = [coder decodeDoubleForKey:@"_replaceViewAnimationDuration"]; - _frontViewShadowRadius = [coder decodeDoubleForKey:@"_frontViewShadowRadius"]; - _frontViewShadowOffset = [coder decodeCGSizeForKey:@"_frontViewShadowOffset"]; - _frontViewShadowOpacity = [coder decodeDoubleForKey:@"_frontViewShadowOpacity"]; - _frontViewShadowColor = [coder decodeObjectForKey:@"_frontViewShadowColor"]; - _userInteractionStore = [coder decodeBoolForKey:@"_userInteractionStore"]; - _animationQueue = [NSMutableArray array]; - _draggableBorderWidth = [coder decodeDoubleForKey:@"_draggableBorderWidth"]; - _clipsViewsToBounds = [coder decodeBoolForKey:@"_clipsViewsToBounds"]; - _extendsPointInsideHit = [coder decodeBoolForKey:@"_extendsPointInsideHit"]; - - [self setRearViewController:[coder decodeObjectForKey:@"_rearViewController"]]; - [self setFrontViewController:[coder decodeObjectForKey:@"_frontViewController"]]; - [self setRightViewController:[coder decodeObjectForKey:@"_rightViewController"]]; - - [self setFrontViewPosition:[coder decodeIntForKey: @"_frontViewPosition"]]; - - [super decodeRestorableStateWithCoder:coder]; + _rearViewRevealWidth = [coder decodeDoubleForKey:@"_rearViewRevealWidth"]; + _rearViewRevealOverdraw = [coder decodeDoubleForKey:@"_rearViewRevealOverdraw"]; + _rearViewRevealDisplacement = [coder decodeDoubleForKey:@"_rearViewRevealDisplacement"]; + _rightViewRevealWidth = [coder decodeDoubleForKey:@"_rightViewRevealWidth"]; + _rightViewRevealOverdraw = [coder decodeDoubleForKey:@"_rightViewRevealOverdraw"]; + _rightViewRevealDisplacement = [coder decodeDoubleForKey:@"_rightViewRevealDisplacement"]; + _bounceBackOnOverdraw = [coder decodeBoolForKey:@"_bounceBackOnOverdraw"]; + _bounceBackOnLeftOverdraw = [coder decodeBoolForKey:@"_bounceBackOnLeftOverdraw"]; + _stableDragOnOverdraw = [coder decodeBoolForKey:@"_stableDragOnOverdraw"]; + _stableDragOnLeftOverdraw = [coder decodeBoolForKey:@"_stableDragOnLeftOverdraw"]; + _presentFrontViewHierarchically = [coder decodeBoolForKey:@"_presentFrontViewHierarchically"]; + _quickFlickVelocity = [coder decodeDoubleForKey:@"_quickFlickVelocity"]; + _toggleAnimationDuration = [coder decodeDoubleForKey:@"_toggleAnimationDuration"]; + _toggleAnimationType = [coder decodeIntegerForKey:@"_toggleAnimationType"]; + _springDampingRatio = [coder decodeDoubleForKey:@"_springDampingRatio"]; + _replaceViewAnimationDuration = [coder decodeDoubleForKey:@"_replaceViewAnimationDuration"]; + _frontViewShadowRadius = [coder decodeDoubleForKey:@"_frontViewShadowRadius"]; + _frontViewShadowOffset = [coder decodeCGSizeForKey:@"_frontViewShadowOffset"]; + _frontViewShadowOpacity = [coder decodeDoubleForKey:@"_frontViewShadowOpacity"]; + _frontViewShadowColor = [coder decodeObjectForKey:@"_frontViewShadowColor"]; + _userInteractionStore = [coder decodeBoolForKey:@"_userInteractionStore"]; + _animationQueue = [NSMutableArray array]; + _draggableBorderWidth = [coder decodeDoubleForKey:@"_draggableBorderWidth"]; + _clipsViewsToBounds = [coder decodeBoolForKey:@"_clipsViewsToBounds"]; + _extendsPointInsideHit = [coder decodeBoolForKey:@"_extendsPointInsideHit"]; + + [self setRearViewController:[coder decodeObjectForKey:@"_rearViewController"]]; + [self setFrontViewController:[coder decodeObjectForKey:@"_frontViewController"]]; + [self setRightViewController:[coder decodeObjectForKey:@"_rightViewController"]]; + + [self setFrontViewPosition:[coder decodeIntForKey: @"_frontViewPosition"]]; + + [super decodeRestorableStateWithCoder:coder]; } - (void)applicationFinishedRestoringState { - // nothing to do at this stage + // nothing to do at this stage } @@ -1824,10 +1829,10 @@ @implementation UIViewController(SWRevealViewController) - (SWRevealViewController*)revealViewController { - UIViewController *parent = self; - Class revealClass = [SWRevealViewController class]; - while ( nil != (parent = [parent parentViewController]) && ![parent isKindOfClass:revealClass] ) {} - return (id)parent; + UIViewController *parent = self; + Class revealClass = [SWRevealViewController class]; + while ( nil != (parent = [parent parentViewController]) && ![parent isKindOfClass:revealClass] ) {} + return (id)parent; } @end @@ -1846,23 +1851,23 @@ @implementation SWRevealViewControllerSegueSetController - (void)perform { - SWRevealControllerOperation operation = SWRevealControllerOperationNone; - - NSString *identifier = self.identifier; - SWRevealViewController *rvc = self.sourceViewController; - UIViewController *dvc = self.destinationViewController; - - if ( [identifier isEqualToString:SWSegueFrontIdentifier] ) - operation = SWRevealControllerOperationReplaceFrontController; - - else if ( [identifier isEqualToString:SWSegueRearIdentifier] ) - operation = SWRevealControllerOperationReplaceRearController; - - else if ( [identifier isEqualToString:SWSegueRightIdentifier] ) - operation = SWRevealControllerOperationReplaceRightController; - - if ( operation != SWRevealControllerOperationNone ) - [rvc _performTransitionOperation:operation withViewController:dvc animated:NO]; + SWRevealControllerOperation operation = SWRevealControllerOperationNone; + + NSString *identifier = self.identifier; + SWRevealViewController *rvc = self.sourceViewController; + UIViewController *dvc = self.destinationViewController; + + if ( [identifier isEqualToString:SWSegueFrontIdentifier] ) + operation = SWRevealControllerOperationReplaceFrontController; + + else if ( [identifier isEqualToString:SWSegueRearIdentifier] ) + operation = SWRevealControllerOperationReplaceRearController; + + else if ( [identifier isEqualToString:SWSegueRightIdentifier] ) + operation = SWRevealControllerOperationReplaceRightController; + + if ( operation != SWRevealControllerOperationNone ) + [rvc _performTransitionOperation:operation withViewController:dvc animated:NO]; } @end @@ -1874,9 +1879,9 @@ @implementation SWRevealViewControllerSeguePushController - (void)perform { - SWRevealViewController *rvc = [self.sourceViewController revealViewController]; - UIViewController *dvc = self.destinationViewController; - [rvc pushFrontViewController:dvc animated:YES]; + SWRevealViewController *rvc = [self.sourceViewController revealViewController]; + UIViewController *dvc = self.destinationViewController; + [rvc pushFrontViewController:dvc animated:YES]; } @end @@ -1903,7 +1908,7 @@ - (void)perform //{ // // This method is required for compatibility with SWRevealViewControllerSegue, now deprecated. // // It can be simply removed when using SWRevealViewControllerSegueSetController and SWRevealViewControlerSeguePushController -// +// // NSString *identifier = segue.identifier; // if ( [segue isKindOfClass:[SWRevealViewControllerSegue class]] && sender == nil ) // {