Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 160 lines (117 sloc) 4.987 kb
d45d508 @myell0w Added category on UIView for zooming
authored
1 //
2 // UIView+MTZoom.m
3 // MTZoomWindow
4 //
5 // Created by Tretter Matthias on 23.10.11.
6 // Copyright (c) 2011 NOUS Wissensmanagement GmbH. All rights reserved.
7 //
8
9 #import "UIView+MTZoom.h"
10 #import "MTZoomWindow.h"
11 #import <objc/runtime.h>
12
7312501 @myell0w Convert to modern Objective-C Syntax
authored
13
1c6e3c5 @myell0w Finished redesign
authored
14 #define kMTDefaultZoomedAutoresizingMask UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
15
7312501 @myell0w Convert to modern Objective-C Syntax
authored
16
d45d508 @myell0w Added category on UIView for zooming
authored
17 static char wrapKey;
18 static char sizeKey;
1c6e3c5 @myell0w Finished redesign
authored
19 static char autoresizingKey;
d45d508 @myell0w Added category on UIView for zooming
authored
20 static char placeholderKey;
1c6e3c5 @myell0w Finished redesign
authored
21 static char delegateKey;
22
d45d508 @myell0w Added category on UIView for zooming
authored
23
24 @implementation UIView (MTZoom)
25
26 ////////////////////////////////////////////////////////////////////////
393d627 @myell0w Shorthand to toggle zoom state of UIView
authored
27 #pragma mark - Zooming
d45d508 @myell0w Added category on UIView for zooming
authored
28 ////////////////////////////////////////////////////////////////////////
29
30 - (void)zoomIn {
31 MTZoomWindow *zoomWindow = [MTZoomWindow sharedWindow];
32
1c6e3c5 @myell0w Finished redesign
authored
33 if (!zoomWindow.zoomedIn) {
34 UIView *superview = self.superview;
15bbb90 @myell0w Converted to ARC
authored
35 UIView *placeholderView = [[UIView alloc] initWithFrame:self.frame];
1c6e3c5 @myell0w Finished redesign
authored
36
37 // setup invisible copy of self
38 placeholderView.autoresizingMask = self.autoresizingMask;
39 [superview insertSubview:placeholderView belowSubview:self];
40 self.zoomPlaceholderView = placeholderView;
41
42 [self mt_callDelegateWillZoomIn];
43
44 // Zoom view into fullscreen-mode and call delegate
45 [zoomWindow zoomView:self toSize:self.zoomedSize];
d45d508 @myell0w Added category on UIView for zooming
authored
46 }
47 }
48
1c6e3c5 @myell0w Finished redesign
authored
49 - (void)zoomOut {
d45d508 @myell0w Added category on UIView for zooming
authored
50 MTZoomWindow *zoomWindow = [MTZoomWindow sharedWindow];
51
1c6e3c5 @myell0w Finished redesign
authored
52 [self mt_callDelegateWillZoomOut];
d45d508 @myell0w Added category on UIView for zooming
authored
53
1c6e3c5 @myell0w Finished redesign
authored
54 // zoom view back to original frame and call delegate
55 [zoomWindow zoomOut];
d45d508 @myell0w Added category on UIView for zooming
authored
56 }
57
393d627 @myell0w Shorthand to toggle zoom state of UIView
authored
58 - (void)toggleZoomState {
59 if (self.zoomedIn) {
60 [self zoomOut];
61 } else {
62 [self zoomIn];
63 }
64 }
65
d45d508 @myell0w Added category on UIView for zooming
authored
66 ////////////////////////////////////////////////////////////////////////
393d627 @myell0w Shorthand to toggle zoom state of UIView
authored
67 #pragma mark - Properties
d45d508 @myell0w Added category on UIView for zooming
authored
68 ////////////////////////////////////////////////////////////////////////
69
70 - (void)setWrapInScrollviewWhenZoomed:(BOOL)wrapInScrollviewWhenZoomed {
7312501 @myell0w Convert to modern Objective-C Syntax
authored
71 objc_setAssociatedObject(self, &wrapKey, @(wrapInScrollviewWhenZoomed), OBJC_ASSOCIATION_RETAIN);
d45d508 @myell0w Added category on UIView for zooming
authored
72 }
73
74 - (BOOL)isWrappedInScrollviewWhenZoomed {
75 BOOL wrapSetByUser = [objc_getAssociatedObject(self, &wrapKey) boolValue];
76
77 // scrollviews don't get wrapped in another scrollview
78 return wrapSetByUser && ![self isKindOfClass:[UIScrollView class]] && ![self isKindOfClass:NSClassFromString(@"MKMapView")];
79 }
80
81 - (void)setZoomedSize:(CGSize)zoomedSize {
82 objc_setAssociatedObject(self, &sizeKey, [NSValue valueWithCGSize:zoomedSize], OBJC_ASSOCIATION_RETAIN);
83 }
84
85 - (CGSize)zoomedSize {
86 return [objc_getAssociatedObject(self, &sizeKey) CGSizeValue];
87 }
88
1c6e3c5 @myell0w Finished redesign
authored
89 - (void)setZoomedAutoresizingMask:(UIViewAutoresizing)zoomedAutoresizingMask {
7312501 @myell0w Convert to modern Objective-C Syntax
authored
90 objc_setAssociatedObject(self, &autoresizingKey, @(zoomedAutoresizingMask), OBJC_ASSOCIATION_RETAIN);
1c6e3c5 @myell0w Finished redesign
authored
91 }
92
93 - (UIViewAutoresizing)zoomedAutoresizingMask {
94 id autoresizingNumber = objc_getAssociatedObject(self, &autoresizingKey);
95
96 if (autoresizingNumber == nil) {
97 return kMTDefaultZoomedAutoresizingMask;
98 }
99
100 return (UIViewAutoresizing)[autoresizingNumber intValue];
101 }
102
103 - (void)setZoomDelegate:(id<MTZoomWindowDelegate>)zoomDelegate {
104 objc_setAssociatedObject(self, &delegateKey, zoomDelegate, OBJC_ASSOCIATION_ASSIGN);
105 }
106
107 - (id<MTZoomWindowDelegate>)zoomDelegate {
108 return objc_getAssociatedObject(self, &delegateKey);
109 }
110
393d627 @myell0w Shorthand to toggle zoom state of UIView
authored
111 - (BOOL)isZoomedIn {
112 return [MTZoomWindow sharedWindow].zoomedIn && [MTZoomWindow sharedWindow].zoomedView == self;
113 }
114
d45d508 @myell0w Added category on UIView for zooming
authored
115 - (void)setZoomPlaceholderView:(UIView *)zoomPlaceholderView {
116 objc_setAssociatedObject(self, &placeholderKey, zoomPlaceholderView, OBJC_ASSOCIATION_RETAIN);
117 }
118
119 - (UIView *)zoomPlaceholderView {
120 return (UIView *)objc_getAssociatedObject(self, &placeholderKey);
121 }
122
1c6e3c5 @myell0w Finished redesign
authored
123 ////////////////////////////////////////////////////////////////////////
7312501 @myell0w Convert to modern Objective-C Syntax
authored
124 #pragma mark - Private Delegate Calls
1c6e3c5 @myell0w Finished redesign
authored
125 ////////////////////////////////////////////////////////////////////////
126
127 - (void)mt_callDelegateWillZoomIn {
128 id<MTZoomWindowDelegate> delegate = self.zoomDelegate;
129
130 if ([delegate respondsToSelector:@selector(zoomWindow:willZoomInView:)]) {
131 [delegate zoomWindow:[MTZoomWindow sharedWindow] willZoomInView:self];
132 }
133 }
134
135 - (void)mt_callDelegateDidZoomIn {
136 id<MTZoomWindowDelegate> delegate = self.zoomDelegate;
137
138 if ([delegate respondsToSelector:@selector(zoomWindow:didZoomInView:)]) {
139 [delegate zoomWindow:[MTZoomWindow sharedWindow] didZoomInView:self];
140 }
141 }
142
143 - (void)mt_callDelegateWillZoomOut {
144 id<MTZoomWindowDelegate> delegate = self.zoomDelegate;
145
146 if ([delegate respondsToSelector:@selector(zoomWindow:willZoomOutView:)]) {
147 [delegate zoomWindow:[MTZoomWindow sharedWindow] willZoomOutView:self];
148 }
149 }
150
151 - (void)mt_callDelegateDidZoomOut {
152 id<MTZoomWindowDelegate> delegate = self.zoomDelegate;
153
154 if ([delegate respondsToSelector:@selector(zoomWindow:didZoomOutView:)]) {
155 [delegate zoomWindow:[MTZoomWindow sharedWindow] didZoomOutView:self];
156 }
157 }
158
d45d508 @myell0w Added category on UIView for zooming
authored
159 @end
Something went wrong with that request. Please try again.