forked from khanhduytran0/FrontBoardAppLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLauncherViewController.m
64 lines (52 loc) · 2.36 KB
/
LauncherViewController.m
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
#import "DecoratedAppSceneView.h"
#import "LauncherViewController.h"
#import "ViewController.h"
@interface LauncherViewController ()
@property(nonatomic) NSMutableArray<LSApplicationProxy *> *apps;
@end
@implementation LauncherViewController
- (void)loadView {
[super loadView];
self.view.backgroundColor = UIColor.systemBackgroundColor;
self.title = @"FrontBoardAppLauncher";
self.apps = LSApplicationWorkspace.defaultWorkspace.allInstalledApplications.mutableCopy;
[self.apps sortUsingDescriptors:@[
[NSSortDescriptor sortDescriptorWithKey:@"localizedShortName" ascending:YES],
]];
}
- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellID = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
cell.textLabel.text = self.apps[indexPath.row].localizedShortName;
cell.detailTextLabel.text = self.apps[indexPath.row].bundleIdentifier;
cell.imageView.image = [UIImage _applicationIconImageForBundleIdentifier:cell.detailTextLabel.text format:0 scale:UIScreen.mainScreen.scale];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
DecoratedAppSceneView *view = [[DecoratedAppSceneView alloc] initWithBundleID:self.apps[indexPath.row].bundleIdentifier];
CGRect origFrame = view.frame;
CGRect cellFrame = view.frame;
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cellFrame.origin = [cell.superview convertPoint:cell.frame.origin toView:self.navigationController.parentViewController.view];
cellFrame.size = cell.frame.size;
view.alpha = 0;
view.frame = cellFrame;
view.backgroundColor = [UIColor blackColor];
[self.navigationController.parentViewController.view addSubview:view];
[UIView animateWithDuration:0.4
animations:^{
view.alpha = 1;
view.frame = origFrame;
} completion:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.apps.count;
}
@end