Skip to content

Commit

Permalink
state restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Lluch committed Jul 16, 2014
1 parent 34f7072 commit ebc5a95
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,20 @@ - (void)applicationWillTerminate:(UIApplication *)application
}

#pragma mark state preservation / restoration
- (BOOL) application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder {

- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
return YES;
}

- (BOOL) application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder {
- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
return YES;
}

- (BOOL) application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//[self.window makeKeyAndVisible];
return YES;
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,57 @@ @implementation ColorViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self customSetup];
}


[self.revealButtonItem setTarget: self.revealViewController];
[self.revealButtonItem setAction: @selector( revealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer];
- (void)customSetup
{
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self.revealButtonItem setTarget: revealViewController];
[self.revealButtonItem setAction: @selector( revealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer:revealViewController.panGestureRecognizer];
}

_label.text = _text;
_label.textColor = _color;
}


#pragma mark state preservation / restoration
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"%s", __PRETTY_FUNCTION__);

// TODO save what you need here
[coder encodeObject: _label.text forKey: @"lableText"];
// Save what you need here
[coder encodeObject: _text forKey: @"text"];
[coder encodeObject: _color forKey: @"color"];

[super encodeRestorableStateWithCoder:coder];
}

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"%s", __PRETTY_FUNCTION__);

// TODO restore what you need here
_label.text = [coder decodeObjectForKey: @"labelText"];
// Restore what you need here
_color = [coder decodeObjectForKey: @"color"];
_text = [coder decodeObjectForKey: @"text"];

[super decodeRestorableStateWithCoder:coder];
}

- (void)applicationFinishedRestoringState {

- (void)applicationFinishedRestoringState
{
NSLog(@"%s", __PRETTY_FUNCTION__);


// TODO call whatever function you need to visually restore

// Call whatever function you need to visually restore
[self customSetup];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,48 @@ @implementation MapViewController
- (void)viewDidLoad
{
[super viewDidLoad];

[self.revealButtonItem setTarget: self.revealViewController];
[self.revealButtonItem setAction: @selector( revealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer];
[self customSetup];
}

- (void)customSetup
{
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self.revealButtonItem setTarget: self.revealViewController];
[self.revealButtonItem setAction: @selector( revealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer];
}
}

#pragma mark state preservation / restoration
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"%s", __PRETTY_FUNCTION__);

// TODO save what you need here
// Save what you need here

[super encodeRestorableStateWithCoder:coder];
}

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"%s", __PRETTY_FUNCTION__);

// TODO restore what you need here
// Restore what you need here

[super decodeRestorableStateWithCoder:coder];
}

- (void)applicationFinishedRestoringState {

- (void)applicationFinishedRestoringState
{
NSLog(@"%s", __PRETTY_FUNCTION__);

// TODO call whatever function you need to visually restore
// Call whatever function you need to visually restore
[self customSetup];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
<inferredMetricsTieBreakers>
<segue reference="oNh-lZ-ivI"/>
<segue reference="Wxg-jn-KPh"/>
<segue reference="oNh-lZ-ivI"/>
</inferredMetricsTieBreakers>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!--Reveal View Controller-->
<scene sceneID="5">
<objects>
<viewController id="2" customClass="SWRevealViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="SWRevealViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="2" customClass="SWRevealViewController" sceneMemberID="viewController">
<connections>
<segue destination="vRn-8p-pLv" kind="custom" identifier="sw_rear" customClass="SWRevealViewControllerSegueSetController" id="tdg-ex-6WR"/>
<segue destination="fWZ-H6-3Jr" kind="custom" identifier="sw_front" customClass="SWRevealViewControllerSegueSetController" id="bla-Jd-Bu2"/>
Expand All @@ -21,7 +21,7 @@
<!--Navigation Controller-->
<scene sceneID="b5Y-SE-MeC">
<objects>
<navigationController definesPresentationContext="YES" id="fWZ-H6-3Jr" sceneMemberID="viewController">
<navigationController storyboardIdentifier="NavigationControllerMap" definesPresentationContext="YES" useStoryboardIdentifierAsRestorationIdentifier="YES" id="fWZ-H6-3Jr" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Xkz-rr-sTC">
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
Expand All @@ -36,7 +36,7 @@
<!--Map View Controller - Map-->
<scene sceneID="9dn-3g-hds">
<objects>
<viewController id="IHS-Te-pvE" customClass="MapViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="MapViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="IHS-Te-pvE" customClass="MapViewController" sceneMemberID="viewController">
<mapView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" id="E6O-iX-rep">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand All @@ -56,7 +56,7 @@
<!--Color View Controller - Color-->
<scene sceneID="vqL-qd-ja9">
<objects>
<viewController id="7k1-p9-rbO" customClass="ColorViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="ColorViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="7k1-p9-rbO" customClass="ColorViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="aUE-BR-SVC"/>
<viewControllerLayoutGuide type="bottom" id="5RF-NJ-TaK"/>
Expand Down Expand Up @@ -90,7 +90,7 @@
<!--Menu View Controller-->
<scene sceneID="cdx-7p-qaC">
<objects>
<tableViewController id="vRn-8p-pLv" customClass="MenuViewController" sceneMemberID="viewController">
<tableViewController storyboardIdentifier="MenuViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="vRn-8p-pLv" customClass="MenuViewController" sceneMemberID="viewController">
<tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="DAb-w1-9EO">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -180,7 +180,7 @@
<!--Navigation Controller-->
<scene sceneID="Ha0-6q-JcM">
<objects>
<navigationController definesPresentationContext="YES" id="vjx-U5-Non" sceneMemberID="viewController">
<navigationController storyboardIdentifier="NavigationControllerColor" definesPresentationContext="YES" useStoryboardIdentifierAsRestorationIdentifier="YES" id="vjx-U5-Non" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Zt4-Qm-0EX">
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
Expand Down
9 changes: 7 additions & 2 deletions SWRevealViewController/SWRevealViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
RELEASE NOTES
- New properties 'toggleAnimationType', 'springDampingRatio'
Version 2.2.0
- State restoration support.
- Reverted panGestureRecognizer implementation to before v2.1.0 (works better).
- New properties 'toggleAnimationType', 'springDampingRatio'. Default reveal animation is 'Spring'
Version 2.1.1 (Current Version)
Expand Down Expand Up @@ -167,7 +172,7 @@ typedef NS_ENUM( NSInteger, FrontViewPosition)
typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType)
{
SWRevealToggleAnimationTypeSpring, // <- produces a spring based animation
SWRevealToggleAnimationTypeEaseOut, // <- produces a simple ease out curve animation
SWRevealToggleAnimationTypeEaseOut, // <- produces an ease out curve animation
};


Expand Down
Loading

0 comments on commit ebc5a95

Please sign in to comment.