-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotatingBackgroundView.m
56 lines (40 loc) · 1.58 KB
/
RotatingBackgroundView.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
//
// RotatingBackgroundView.m
// Grace World
//
// Created by John Detloff on 1/28/13.
// Copyright (c) 2013 Uebie. All rights reserved.
//
#import "RotatingBackgroundView.h"
#import "WorldDataStore.h"
#import "OrbitalCoordinate.h"
#import <QuartzCore/QuartzCore.h>
@implementation RotatingBackgroundView {
CGPoint _rotationalCenter;
}
- (void)shiftBy:(CGFloat)distance {
_rotatingImageView.transform = CGAffineTransformRotate(_rotatingImageView.transform, distance);
}
- (CGFloat)angle {
return atan2(_rotatingImageView.transform.b, _rotatingImageView.transform.a) + M_PI/2;
}
- (void)setRotatingImage:(UIImage *)image size:(CGSize)imageSize anchorPoint:(CGPoint)anchorPoint position:(CGPoint)position {
_rotationalCenter = anchorPoint;
UIImageView *layer = [[UIImageView alloc] initWithImage:image];
layer.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
layer.center = position;
[self addSubview:layer];
_rotatingImageView = layer;
_rotatingImageView.layer.anchorPoint = CGPointMake(anchorPoint.x / imageSize.width, anchorPoint.y / imageSize.height);
}
- (void)addProps:(NSArray *)props {
for (RadialElement *prop in props) {
UIView *display = prop.display;
CGFloat anchorPointY = (prop.coordinate.height)/display.frame.size.height;
display.layer.anchorPoint = CGPointMake(0.5, anchorPointY);
display.center = _rotationalCenter;
display.transform = CGAffineTransformMakeRotation(-(prop.coordinate.angle - M_PI/2));
[_rotatingImageView addSubview:display];
}
}
@end