-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathControlCenterBottomScrollView.xm
More file actions
111 lines (93 loc) · 3.86 KB
/
ControlCenterBottomScrollView.xm
File metadata and controls
111 lines (93 loc) · 3.86 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
#import "headers.h"
@implementation ControlCenterBottomScrollView
-(id)initWithFrame:(CGRect)frame {
frame = CGRectMake(frame.origin.x + 20, frame.origin.y, frame.size.width - 40, frame.size.height);
self = [super initWithFrame:frame];
if (self) {
CGRect firstPageViewFrame = CGRectMake(0, 0, frame.size.width, frame.size.height);
CGRect secondPageViewFrame = CGRectMake(frame.size.width, 0, frame.size.width, frame.size.height);
CGRect thirdPageViewFrame = CGRectMake(frame.size.width * 2, 0, frame.size.width, frame.size.height);
UIView *view = [[UIView alloc] initWithFrame:firstPageViewFrame];
NSInteger totalSections = 0;
CGFloat currentOriginY = 0;
if ([SCPreferences sharedInstance].bottomSection != nil) {
NSInteger totalBottomSections = [[SCPreferences sharedInstance].bottomSection count];
for (NSInteger i = 0; i < totalBottomSections; i++) {
Class currentClass = [[SCPreferences sharedInstance] sectionClass:kBottom withIndex:i];
if (currentClass != [ControlCenterFailureSectionClass class]) {
totalSections++;
CGRect currentFrame = CGRectMake(0, currentOriginY, frame.size.width, 64);
ControlCenterSectionView *currentSection = [[currentClass alloc] initWithFrame:currentFrame];
CGFloat additionalHeight = currentSection.frame.size.height - currentFrame.size.height;
frame.size.height += additionalHeight;
currentOriginY += (74 + additionalHeight);
[view addSubview:currentSection];
[currentSection release];
}
}
}
if (totalSections == 0) {
thirdPageViewFrame.origin.x = secondPageViewFrame.origin.x;
secondPageViewFrame.origin.x = firstPageViewFrame.origin.x;
firstPageViewFrame = CGRectZero;
view.frame = CGRectZero;
}
if (frame.size.height < 152)
frame.size.height = 152;
firstPageViewFrame.size.height = frame.size.height;
secondPageViewFrame.size.height = frame.size.height;
thirdPageViewFrame.size.height = frame.size.height;
view.frame = firstPageViewFrame;
ControlCenterMediaSectionView *mediaSection = [[ControlCenterMediaSectionView alloc] initWithFrame:secondPageViewFrame];
[mediaSection setupRoutingPageWithFrame:thirdPageViewFrame];
[self addSubview:view];
[self addSubview:mediaSection];
self.frame = frame;
[self resetupScrollWidth:NO];
self.pagingEnabled = YES;
[self setShowsHorizontalScrollIndicator:NO];
[view release];
[mediaSection release];
}
return self;
}
-(void)resetupScrollWidth:(BOOL)playing {
CGFloat scrollWidth = 0;
BOOL removeDevicesPage = [SCPreferences sharedInstance].isRemoveDevicesPagesEnabled;
if (playing)
scrollWidth = self.frame.size.width * (removeDevicesPage ? 2 : 3);
else if ([SCPreferences sharedInstance].isRemoveMediaAndDevicesPagesEnabled)
scrollWidth = self.frame.size.width;
else
scrollWidth = self.frame.size.width * (removeDevicesPage ? 2 : 3);
self.contentSize = CGSizeMake(scrollWidth, self.frame.size.height);
}
-(void)scrollToPage:(NSInteger)page animated:(BOOL)animated {
CGRect frame = self.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[self scrollRectToVisible:frame animated:animated];
}
-(NSInteger)currentVisiblePage {
return (self.contentOffset.x + self.bounds.size.width / 2) / self.bounds.size.width;
}
-(NSInteger)mediaPage {
if (self.contentSize.width == self.frame.size.width * 2)
return 0;
return 1;
}
-(NSInteger)defaultPage {
if (self.contentSize.width == self.frame.size.width * 2)
return [SCPreferences sharedInstance].defaultPage - 1;
return [SCPreferences sharedInstance].defaultPage;
}
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *result = [super hitTest:point withEvent:event];
if ([result isKindOfClass:[%c(UISlider) class]]) {
self.scrollEnabled = NO;
} else {
self.scrollEnabled = YES;
}
return result;
}
@end