forked from ViewDeck/ViewDeck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChoiceController.m
More file actions
147 lines (116 loc) · 5.18 KB
/
ChoiceController.m
File metadata and controls
147 lines (116 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// ChoiceController.m
// FeaturesExample
//
#import "ChoiceController.h"
#import "PhotosController.h"
#import "SelectionController.h"
#import "IIViewDeckController.h"
@interface ChoiceController () <IIViewDeckControllerDelegate> {
IIViewDeckPanningMode _panning;
IIViewDeckCenterHiddenInteractivity _centerHidden;
IIViewDeckNavigationControllerBehavior _navBehavior;
IIViewDeckSizeMode _sizeMode;
BOOL _elastic;
CGFloat _maxLedge;
}
@end
@implementation ChoiceController
@synthesize panningView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_panning = IIViewDeckNoPanning;
_centerHidden = IIViewDeckCenterHiddenUserInteractive;
_navBehavior = IIViewDeckNavigationControllerContained;
_sizeMode = IIViewDeckLedgeSizeMode;
_elastic = YES;
_maxLedge = 0;
}
return self;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Features example";
self.view.backgroundColor = [UIColor colorWithWhite:0.3 alpha:1];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES; // UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (IBAction)pressedNavigate:(id)sender {
PhotosController* photosController = [[PhotosController alloc] initWithNibName:@"PhotosController" bundle:nil];
SelectionController* selectionController = [[SelectionController alloc] initWithNibName:@"SelectionController" bundle:nil];
IIViewDeckController* controller = [[IIViewDeckController alloc] initWithCenterViewController:photosController leftViewController:selectionController];
controller.panningMode = _panning;
controller.centerhiddenInteractivity = _centerHidden;
controller.navigationControllerBehavior = _navBehavior;
controller.panningView = self.panningView;
controller.maxSize = _maxLedge > 0 ? self.view.bounds.size.width-_maxLedge : 0;
controller.sizeMode = _sizeMode;
controller.elastic = _elastic;
controller.leftSize = 320;
controller.delegate = self;
[controller openLeftView];
[self.navigationController pushViewController:controller animated:YES];
}
- (IBAction)panningChanged:(id)sender {
UISegmentedControl* control = (UISegmentedControl*)sender;
IIViewDeckPanningMode values[] = { IIViewDeckNoPanning, IIViewDeckFullViewPanning, IIViewDeckNavigationBarPanning, IIViewDeckPanningViewPanning, IIViewDeckDelegatePanning, IIViewDeckNavigationBarOrOpenCenterPanning };
_panning = values[control.selectedSegmentIndex];
}
- (IBAction)centerHiddenChanged:(id)sender {
UISegmentedControl* control = (UISegmentedControl*)sender;
IIViewDeckCenterHiddenInteractivity values[] = { IIViewDeckCenterHiddenUserInteractive, IIViewDeckCenterHiddenNotUserInteractive, IIViewDeckCenterHiddenNotUserInteractiveWithTapToClose, IIViewDeckCenterHiddenNotUserInteractiveWithTapToCloseBouncing };
_centerHidden = values[control.selectedSegmentIndex];
}
- (IBAction)navigationChanged:(id)sender {
UISegmentedControl* control = (UISegmentedControl*)sender;
IIViewDeckNavigationControllerBehavior values[] = { IIViewDeckNavigationControllerContained, IIViewDeckNavigationControllerIntegrated };
_navBehavior = values[control.selectedSegmentIndex];
}
- (IBAction)rotationChanged:(id)sender {
UISegmentedControl* control = (UISegmentedControl*)sender;
IIViewDeckSizeMode values[] = { IIViewDeckLedgeSizeMode, IIViewDeckViewSizeMode };
_sizeMode = values[control.selectedSegmentIndex];
}
- (IBAction)elasticChanged:(id)sender {
_elastic = ((UISwitch*)sender).on;
}
- (IBAction)maxLedgeChanged:(id)sender {
_maxLedge = ((UISlider*)sender).value;
}
#define 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 } \
}; \
})
- (BOOL)viewDeckController:(IIViewDeckController *)viewDeckController shouldPan:(UIPanGestureRecognizer *)panGestureRecognizer {
CGRect halfRect = self.navigationController.navigationBar.bounds;
halfRect = CGRectOffsetRightAndShrink(halfRect, halfRect.size.width/2);
UIView* flash = [UIView new];
BOOL ok = CGRectContainsPoint(halfRect, [panGestureRecognizer locationInView:self.navigationController.navigationBar]);
if (ok) {
flash.frame = halfRect;
flash.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.5];
}
else {
flash.frame = self.navigationController.navigationBar.bounds;
flash.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];
}
[self.navigationController.navigationBar addSubview:flash];
[UIView animateWithDuration:0.3 animations:^{
flash.alpha = 0;
} completion:^(BOOL finished) {
[flash removeFromSuperview];
}];
return ok;
}
@end