Permalink
Browse files

added bounce on close, default animation duration to tray view

  • Loading branch information...
1 parent ae6cda7 commit 91f9c40c12157bf42b000775e210a2e2ba4849b4 @JeremyOT committed Mar 28, 2012
View
@@ -21,11 +21,13 @@ typedef enum {
@property (nonatomic, readonly, getter = isDisplayed) BOOL displayed;
@property (nonatomic, retain) UIImage *backgroundImage;
@property (nonatomic, assign) TrayPosition trayPosition;
+@property (nonatomic) BOOL bouncesOnClose;
+@property (nonatomic) NSTimeInterval defaultAnimationDuration;
-(void)showInWindow:(UIWindow*)window;
-(void)showInWindow:(UIWindow*)window withDuration:(NSTimeInterval)duration;
-(void)hide;
--(void)hideWithDuration:(NSTimeInterval)duration;
+-(void)hideWithDuration:(NSTimeInterval)duration bounce:(BOOL)bounce;
-(void)setUIInterfaceOrientation:(UIInterfaceOrientation)orientation supported:(BOOL)supported;
@end
View
@@ -19,6 +19,8 @@ @implementation TrayView
@synthesize slideView = _slideView;
@synthesize displayed = _displayed;
@synthesize trayPosition = _trayPosition;
+@synthesize bouncesOnClose = _bouncesOnClose;
+@synthesize defaultAnimationDuration = _defaultAnimationDuration;
- (id)initWithFrame:(CGRect)frame {
if (([super initWithFrame:frame])) {
@@ -32,6 +34,7 @@ - (id)initWithFrame:(CGRect)frame {
_supportedOrientations[UIDeviceOrientationFaceUp] = NO;
_supportedOrientations[UIDeviceOrientationFaceDown] = NO;
_orientation = [[UIApplication sharedApplication] statusBarOrientation];
+ _defaultAnimationDuration = 0.25;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
@@ -57,7 +60,7 @@ -(void)setBackgroundImage:(UIImage *)backgroundImage {
}
-(void)showInWindow:(UIWindow *)window {
- [self showInWindow:window withDuration:0.5];
+ [self showInWindow:window withDuration:_defaultAnimationDuration];
}
-(void)showInWindow:(UIWindow *)window withDuration:(NSTimeInterval)duration {
@@ -185,30 +188,57 @@ -(void)showInWindow:(UIWindow *)window withDuration:(NSTimeInterval)duration {
}
-(void)hide {
- [self hideWithDuration:0.5];
+ [self hideWithDuration:_defaultAnimationDuration bounce:_bouncesOnClose];
}
--(void)hideWithDuration:(NSTimeInterval)duration {
+-(void)hideWithDuration:(NSTimeInterval)duration bounce:(BOOL)bounce{
_displayed = NO;
- [UIView animateWithDuration:duration animations:^{
- CGRect frame = _slideView.frame;
- switch (_orientation) {
- case UIInterfaceOrientationLandscapeLeft:
- case UIInterfaceOrientationLandscapeRight:
- frame.origin.y = 0;
- break;
- case UIInterfaceOrientationPortraitUpsideDown:
- case UIInterfaceOrientationPortrait:
- default:
- frame.origin.x = 0;
- break;
- }
- _slideView.frame = frame;
- } completion:^(BOOL finished) {
- [self removeFromSuperview];
- _slideView.clipsToBounds = YES;
- _slideView = nil;
- }];
+ void (^closeAnimation)() = ^{
+ [UIView animateWithDuration:duration animations:^{
+ CGRect frame = _slideView.frame;
+ switch (_orientation) {
+ case UIInterfaceOrientationLandscapeLeft:
+ case UIInterfaceOrientationLandscapeRight:
+ frame.origin.y = 0;
+ break;
+ case UIInterfaceOrientationPortraitUpsideDown:
+ case UIInterfaceOrientationPortrait:
+ default:
+ frame.origin.x = 0;
+ break;
+ }
+ _slideView.frame = frame;
+ } completion:^(BOOL finished) {
+ [self removeFromSuperview];
+ _slideView.clipsToBounds = YES;
+ _slideView = nil;
+ }];
+ };
+ if (bounce) {
+ [UIView animateWithDuration:duration animations:^{
+ CGRect frame = _slideView.frame;
+ switch (_orientation) {
+ case UIInterfaceOrientationLandscapeLeft:
+ frame.origin.y = _trayPosition == TrayPositionLeft ? -frame.size.height : frame.size.height;
+ break;
+ case UIInterfaceOrientationLandscapeRight:
+ frame.origin.y = _trayPosition == TrayPositionLeft ? frame.size.height : -frame.size.height;
+ break;
+ case UIInterfaceOrientationPortraitUpsideDown:
+ frame.origin.x = _trayPosition == TrayPositionLeft ? -frame.size.width : frame.size.width;
+ break;
+ case UIInterfaceOrientationPortrait:
+ default:
+ frame.origin.x = _trayPosition == TrayPositionLeft ? frame.size.width : -frame.size.width;
+ break;
+ }
+ _slideView.frame = frame;
+ } completion: ^(BOOL completed) {
+ closeAnimation();
+ }];
+ } else {
+ closeAnimation();
+ }
}
-(void)setUIInterfaceOrientation:(UIInterfaceOrientation)orientation supported:(BOOL)supported {
@@ -31,6 +31,7 @@ - (void)viewDidLoad
[[SlideMenu sharedMenuRight] setUIInterfaceOrientation:UIInterfaceOrientationLandscapeLeft supported:NO];
[[SlideMenu sharedMenuRight] setUIInterfaceOrientation:UIInterfaceOrientationLandscapeRight supported:NO];
}
+ [[SlideMenu sharedMenuRight] setBouncesOnClose:YES];
BOOL (^block)(SlideMenuItem *item) = ^(SlideMenuItem *item) {
NSLog(@"Clicked: %@", item.title);
return YES;
@@ -99,7 +100,7 @@ -(void)showMenu:(id)sender {
if (!menu.displayed) {
[menu showInWindow:self.view.window];
} else {
- [menu hide];
+ [menu hideWithDuration:menu.defaultAnimationDuration bounce:NO];
}
}
@@ -108,7 +109,7 @@ -(void)showMenuRight:(id)sender {
if (!menu.displayed) {
[menu showInWindow:self.view.window];
} else {
- [menu hide];
+ [menu hideWithDuration:menu.defaultAnimationDuration bounce:NO];
}
}
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="8.00">
<data>
- <int key="IBDocument.SystemTarget">1280</int>
+ <int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11D50</string>
- <string key="IBDocument.InterfaceBuilderVersion">2177</string>
+ <string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.AppKitVersion">1138.32</string>
<string key="IBDocument.HIToolboxVersion">568.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="NS.object.0">1173</string>
+ <string key="NS.object.0">1181</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBUINavigationItem</string>
@@ -43,14 +43,21 @@
<string key="NSFrameSize">{768, 44}</string>
<reference key="NSSuperview" ref="766721923"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:260</string>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<array key="IBUIItems">
<object class="IBUINavigationItem" id="165539418">
<reference key="IBUINavigationBar" ref="138062551"/>
<string key="IBUITitle">Title</string>
<object class="IBUIBarButtonItem" key="IBUILeftBarButtonItem" id="864169666">
- <string key="IBUITitle">Item</string>
+ <string key="IBUITitle">Menu</string>
+ <string key="targetRuntimeIdentifier">IBIPadFramework</string>
+ <int key="IBUIStyle">1</int>
+ <reference key="IBUINavigationItem" ref="165539418"/>
+ </object>
+ <object class="IBUIBarButtonItem" key="IBUIRightBarButtonItem" id="604146317">
+ <string key="IBUITitle">Menu</string>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<int key="IBUIStyle">1</int>
<reference key="IBUINavigationItem" ref="165539418"/>
@@ -63,6 +70,7 @@
<string key="NSFrame">{{0, 20}, {768, 1004}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="138062551"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
@@ -104,6 +112,14 @@
</object>
<int key="connectionID">9</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">showMenuRight:</string>
+ <reference key="source" ref="604146317"/>
+ <reference key="destination" ref="841351856"/>
+ </object>
+ <int key="connectionID">11</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -158,6 +174,7 @@
<reference key="object" ref="165539418"/>
<array class="NSMutableArray" key="children">
<reference ref="864169666"/>
+ <reference ref="604146317"/>
</array>
<reference key="parent" ref="138062551"/>
</object>
@@ -166,13 +183,19 @@
<reference key="object" ref="864169666"/>
<reference key="parent" ref="165539418"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">10</int>
+ <reference key="object" ref="604146317"/>
+ <reference key="parent" ref="165539418"/>
+ </object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
<string key="-1.CustomClassName">SMViewController</string>
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="10.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@@ -184,24 +207,27 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">9</int>
+ <int key="maxID">11</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">SMViewController</string>
<string key="superclassName">UIViewController</string>
- <object class="NSMutableDictionary" key="actions">
- <string key="NS.key.0">showMenu:</string>
- <string key="NS.object.0">id</string>
- </object>
- <object class="NSMutableDictionary" key="actionInfosByName">
- <string key="NS.key.0">showMenu:</string>
- <object class="IBActionInfo" key="NS.object.0">
+ <dictionary class="NSMutableDictionary" key="actions">
+ <string key="showMenu:">id</string>
+ <string key="showMenuRight:">id</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="actionInfosByName">
+ <object class="IBActionInfo" key="showMenu:">
<string key="name">showMenu:</string>
<string key="candidateClassName">id</string>
</object>
- </object>
+ <object class="IBActionInfo" key="showMenuRight:">
+ <string key="name">showMenuRight:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ </dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/SMViewController.h</string>
@@ -211,8 +237,12 @@
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
+ <real value="1296" key="NS.object.0"/>
+ </object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
- <string key="IBCocoaTouchPluginVersion">1173</string>
+ <string key="IBCocoaTouchPluginVersion">1181</string>
</data>
</archive>

0 comments on commit 91f9c40

Please sign in to comment.