-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockView.m
More file actions
102 lines (78 loc) · 2.83 KB
/
ClockView.m
File metadata and controls
102 lines (78 loc) · 2.83 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
//
// ClockBackgroundView.m
// Sleep Blaster touch
//
// Created by Eamon Ford on 12/28/09.
// Copyright 2009 The Byte Factory. All rights reserved.
//
#import "ClockView.h"
#import "ShadowedLabel.h"
@implementation ClockView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
subviewsAreInPortraitMode = NO;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
return self;
}
- (void)layoutSubviews
{
if ((UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) && subviewsAreInPortraitMode) ||
(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) && subviewsAreInPortraitMode == NO) ||
!UIDeviceOrientationIsValidInterfaceOrientation([UIDevice currentDevice].orientation))
{
return;
}
float ratio = [UIScreen mainScreen].bounds.size.height/[UIScreen mainScreen].bounds.size.width;
// This is simply the number of pixels from the top of the screen to the top of the clock image when it's in portrait,
// and centered on the screen.
float yOffset = [UIScreen mainScreen].bounds.size.height/2 - [UIScreen mainScreen].bounds.size.width/ratio/2;
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
ratio = 1.0/ratio;
}
for (int i = 0; i < self.subviews.count; i++)
{
UIView *view = [self.subviews objectAtIndex:i];
CGRect frame = view.frame;
/* if (view == rightSettingsButton)
{
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
frame.origin.x = [UIScreen mainScreen].bounds.size.width - frame.size.width - 10.0;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height - 10.0;
NSLog(@"positioning the button at: %f, %f", frame.origin.x, frame.origin.y);
} else {
frame.origin.x = [UIScreen mainScreen].bounds.size.height - frame.size.width - 10.0;
frame.origin.y = [UIScreen mainScreen].bounds.size.width - frame.size.height - 10.0;
NSLog(@"positioning the button at: %f, %f", frame.origin.x, frame.origin.y);
}
} else*/
if ([view class] != [UIButton class]) {
if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
frame.origin.y -= yOffset;
}
frame.size.width *= ratio;
frame.size.height *= ratio;
frame.origin.x *= ratio;
frame.origin.y *= ratio;
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
frame.origin.y += yOffset;
}
if ([view class] == [ShadowedLabel class])
{
UIFont *originalFont = ((UILabel*)view).font;
UIFont *newFont = [UIFont fontWithName:originalFont.fontName size:originalFont.pointSize*ratio];
((UILabel*)view).font = newFont;
}
}
view.frame = frame;
}
subviewsAreInPortraitMode = !subviewsAreInPortraitMode;
}
- (void)dealloc {
[super dealloc];
}
@end