Skip to content
This repository
Browse code

IISideController doesn't animate frame changes.

You can turn this off by setting animateShrink to YES.
  • Loading branch information...
commit 78f0517cd6169f344f13ca989a245131f3986c4b 1 parent 2c7cbce
Tom Adriaenssen authored December 14, 2012
2  ViewDeck/IISideController.h
@@ -10,6 +10,8 @@
10 10
 
11 11
 @interface IISideController : IIWrapController
12 12
 
  13
+@property (nonatomic, assign) BOOL animatedShrink; // if the shrink action should participate in any ongoing animation. Defaults to NO.
  14
+
13 15
 - (id)initWithViewController:(UIViewController*)controller constrained:(CGFloat)constrainedSize;
14 16
 
15 17
 @end
25  ViewDeck/IISideController.m
@@ -8,6 +8,7 @@
8 8
 
9 9
 #import "IISideController.h"
10 10
 #import "IIViewDeckController.h"
  11
+#import <QuartzCore/QuartzCore.h>
11 12
 
12 13
 #define II_CGRectOffsetLeftAndShrink(rect, offset) ({__typeof__(rect) __r = (rect); __typeof__(offset) __o = (offset); (CGRect) { __r.origin.x + __o, __r.origin.y, __r.size.width-__o, __r.size.height }; })
13 14
 #define II_CGRectOffsetRightAndShrink(rect, offset) ({__typeof__(rect) __r = (rect); __typeof__(offset) __o = (offset); (CGRect) { __r.origin.x, __r.origin.y, __r.size.width-__o, __r.size.height }; })
@@ -25,6 +26,7 @@ @implementation IISideController {
25 26
 - (id)initWithViewController:(UIViewController*)controller constrained:(CGFloat)constrainedSize {
26 27
     if ((self = [super initWithViewController:controller])) {
27 28
         _constrainedSize = constrainedSize;
  29
+        _animatedShrink = NO;
28 30
     }
29 31
     return self;
30 32
 }
@@ -32,12 +34,24 @@ - (id)initWithViewController:(UIViewController*)controller constrained:(CGFloat)
32 34
 - (id)initWithViewController:(UIViewController*)controller {
33 35
     if ((self = [super initWithViewController:controller])) {
34 36
         _constrainedSize = -1;
  37
+        _animatedShrink = NO;
35 38
     }
36 39
     return self;
37 40
 }
38 41
 
  42
+- (void)viewDidLoad {
  43
+    [super viewDidLoad];
  44
+    [self shrinkSide];
  45
+}
  46
+
39 47
 - (void)viewWillAppear:(BOOL)animated {
40 48
     [super viewWillAppear:animated];
  49
+    [CATransaction begin];
  50
+    if (!self.animatedShrink) {
  51
+        [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
  52
+    }
  53
+    self.view.backgroundColor = self.wrappedController.view.backgroundColor;
  54
+    [CATransaction commit];
41 55
     [self shrinkSide];
42 56
 }
43 57
 
@@ -48,15 +62,19 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte
48 62
 
49 63
 - (void)shrinkSide {
50 64
     if (self.viewDeckController) {
  65
+        // we don't want this animated
  66
+        [CATransaction begin];
  67
+        if (!self.animatedShrink) {
  68
+            [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
  69
+        }
  70
+        
51 71
         if (self.viewDeckController.leftController == self) {
52 72
             CGFloat offset = self.view.bounds.size.width - (_constrainedSize > 0 ? _constrainedSize : self.viewDeckController.leftViewSize);
53 73
             self.wrappedController.view.frame = II_CGRectOffsetRightAndShrink(self.view.bounds, offset);
54 74
         }
55 75
         else if (self.viewDeckController.rightController == self) {
56 76
             CGFloat offset = self.view.bounds.size.width - (_constrainedSize > 0 ? _constrainedSize : self.viewDeckController.rightViewSize);
57  
-            NSLog(@"b %@", NSStringFromCGRect(self.wrappedController.view.frame));
58 77
             self.wrappedController.view.frame = II_CGRectOffsetLeftAndShrink(self.view.bounds, offset);
59  
-            NSLog(@"a %@", NSStringFromCGRect(self.wrappedController.view.frame));
60 78
         }
61 79
         else if (self.viewDeckController.topController == self) {
62 80
             CGFloat offset = self.view.bounds.size.height - (_constrainedSize > 0 ? _constrainedSize : self.viewDeckController.topViewSize);
@@ -66,8 +84,9 @@ - (void)shrinkSide {
66 84
             CGFloat offset = self.view.bounds.size.height - (_constrainedSize > 0 ? _constrainedSize : self.viewDeckController.bottomViewSize);
67 85
             self.wrappedController.view.frame = II_CGRectOffsetTopAndShrink(self.view.bounds, offset);
68 86
         }
  87
+        
  88
+        [CATransaction commit];
69 89
     }
70 90
 }
71 91
 
72  
-
73 92
 @end

0 notes on commit 78f0517

Please sign in to comment.
Something went wrong with that request. Please try again.