Permalink
Browse files

Shorthand to toggle zoom state of UIView

  • Loading branch information...
1 parent 9924158 commit 393d627f81563b12454840061ed13287f4c45459 @myell0w committed Dec 25, 2011
Showing with 25 additions and 17 deletions.
  1. +1 −0 MTZoomWindow.h
  2. +6 −11 MTZoomWindow.m
  3. +3 −0 UIView+MTZoom.h
  4. +15 −6 UIView+MTZoom.m
View
1 MTZoomWindow.h
@@ -32,6 +32,7 @@ typedef NSInteger MTZoomGestureMask;
@property (nonatomic, assign) NSTimeInterval animationDuration;
@property (nonatomic, assign) NSTimeInterval animationDelay;
@property (nonatomic, assign) float maximumZoomScale;
+@property (nonatomic, strong, readonly) UIView *zoomedView;
@property (nonatomic, readonly, getter = isZoomedIn) BOOL zoomedIn;
+ (MTZoomWindow *)sharedWindow;
View
17 MTZoomWindow.m
@@ -18,7 +18,7 @@
@interface MTZoomWindow ()
-@property (nonatomic, strong) UIView *zoomedView;
+@property (nonatomic, strong, readwrite) UIView *zoomedView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (unsafe_unretained, nonatomic, readonly) UIView *zoomSuperview;
@property (nonatomic, strong) NSMutableSet *gestureRecognizers;
@@ -45,8 +45,7 @@ @implementation MTZoomWindow
@synthesize maximumZoomScale = maximumZoomScale_;
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark Lifecycle
+#pragma mark - Lifecycle
////////////////////////////////////////////////////////////////////////
- (id)initWithFrame:(CGRect)frame {
@@ -106,8 +105,7 @@ - (void)dealloc {
}
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark MTZoomWindow
+#pragma mark - MTZoomWindow
////////////////////////////////////////////////////////////////////////
- (void)zoomView:(UIView *)view toSize:(CGSize)size {
@@ -232,8 +230,7 @@ - (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
}
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark UIScrollViewDelegate
+#pragma mark - UIScrollViewDelegate
////////////////////////////////////////////////////////////////////////
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
@@ -249,8 +246,7 @@ - (void)scrollViewDidZoom:(UIScrollView *)scrollView {
}
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark Rotation
+#pragma mark - Rotation
////////////////////////////////////////////////////////////////////////
- (void)setupForOrientation:(UIInterfaceOrientation)orientation forceLayout:(BOOL)forceLayout {
@@ -371,8 +367,7 @@ - (void)orientationDidChange:(NSNotification *)note {
}
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark Singleton definitons
+#pragma mark - Singleton definitons
////////////////////////////////////////////////////////////////////////
static MTZoomWindow *sharedMTZoomWindow = nil;
View
3 UIView+MTZoom.h
@@ -28,8 +28,11 @@
@property (nonatomic, retain) UIView *zoomPlaceholderView;
/** The delegate for zooming */
@property (nonatomic, assign) id<MTZoomWindowDelegate> zoomDelegate;
+/** Flag that indicates if the view is currently zoomed in */
+@property (nonatomic, readonly, getter = isZoomedIn) BOOL zoomedIn;
- (void)zoomIn;
- (void)zoomOut;
+- (void)toggleZoomState;
@end
View
21 UIView+MTZoom.m
@@ -30,8 +30,7 @@ - (void)mt_callDelegateDidZoomOut;
@implementation UIView (MTZoom)
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark Zooming
+#pragma mark - Zooming
////////////////////////////////////////////////////////////////////////
- (void)zoomIn {
@@ -62,9 +61,16 @@ - (void)zoomOut {
[zoomWindow zoomOut];
}
+- (void)toggleZoomState {
+ if (self.zoomedIn) {
+ [self zoomOut];
+ } else {
+ [self zoomIn];
+ }
+}
+
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark Properties
+#pragma mark - Properties
////////////////////////////////////////////////////////////////////////
- (void)setWrapInScrollviewWhenZoomed:(BOOL)wrapInScrollviewWhenZoomed {
@@ -108,6 +114,10 @@ - (void)setZoomDelegate:(id<MTZoomWindowDelegate>)zoomDelegate {
return objc_getAssociatedObject(self, &delegateKey);
}
+- (BOOL)isZoomedIn {
+ return [MTZoomWindow sharedWindow].zoomedIn && [MTZoomWindow sharedWindow].zoomedView == self;
+}
+
- (void)setZoomPlaceholderView:(UIView *)zoomPlaceholderView {
objc_setAssociatedObject(self, &placeholderKey, zoomPlaceholderView, OBJC_ASSOCIATION_RETAIN);
}
@@ -117,8 +127,7 @@ - (UIView *)zoomPlaceholderView {
}
////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark Delegate Calls
+#pragma mark - Delegate Calls
////////////////////////////////////////////////////////////////////////
- (void)mt_callDelegateWillZoomIn {

0 comments on commit 393d627

Please sign in to comment.