-
Notifications
You must be signed in to change notification settings - Fork 5
/
PWWindow.m
95 lines (75 loc) · 2.31 KB
/
PWWindow.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
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
//
// ProWidgets
//
// 1.0.0
//
// Created by Alan Yip on 18 Jan 2014
// Copyright 2014 Alan Yip. All rights reserved.
//
#import "PWWindow.h"
#import "PWController.h"
#import "PWWidgetController.h"
#import "PWContainerView.h"
#import "PWView.h"
#import "PWMiniView.h"
@implementation PWWindow
- (instancetype)init {
if (self = [super init]) {
// Window Levels
// (Cut/Copy) UITextEffectsWindow 2100
// (Undo/Cancel) ~Alert window 1996
// Notification Center 1056
// Control Center 1056
// === PWWindow === 1055
// Lock Alert Window 1050
// UIWindowLevelStatusBar 1000
self.windowLevel = 1055.0;
self.backgroundColor = [UIColor clearColor];
self.userInteractionEnabled = YES;
self.frame = [[UIScreen mainScreen] bounds];
self.hidden = NO;
[self adjustLayout];
}
return self;
}
- (void)adjustLayout {
UIInterfaceOrientation orientation = [[PWController sharedInstance] currentInterfaceOrientation];
if (!_adjustedLayout || _currentOrientation != orientation) {
_adjustedLayout = YES;
_currentOrientation = orientation;
CGAffineTransform transform = [self orientationToTransform:orientation];
LOG(@"PWWindow adjustLayout <orientation: %d>", (int)orientation);
PWView *mainView = [PWController sharedInstance].mainView;
mainView.transform = CGAffineTransformIdentity;
mainView.transform = transform;
mainView.frame = self.bounds;
[mainView setNeedsLayout];
[mainView layoutIfNeeded];
[PWWidgetController adjustLayoutForAllControllers];
}
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *result = [super hitTest:point withEvent:event];
if (result == self) {
return nil;
} else {
return result;
}
}
- (CGAffineTransform)orientationToTransform:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeRight) {
return CGAffineTransformMakeRotation(M_PI_2);
} else if (orientation == UIInterfaceOrientationLandscapeLeft) {
return CGAffineTransformMakeRotation(-M_PI_2);
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
return CGAffineTransformMakeRotation(M_PI);
} else if (orientation == UIInterfaceOrientationPortrait) {
return CGAffineTransformMakeRotation(0.0);
}
return CGAffineTransformIdentity;
}
- (void)dealloc {
DEALLOCLOG;
[super dealloc];
}
@end