Graphics Reference
In-Depth Information
@property
(
nonatomic
,
strong
)
IBOutlet
UIScrollView
*scrollView;
@end
@implementation
ViewController
- (
void
)viewDidLoad
{
[
super
viewDidLoad
];
//set content size
self
.
scrollView
.
contentSize
=
CGSizeMake
((
WIDTH
-
1
)*
SPACING
,
(
HEIGHT
-
1
)*
SPACING
);
//set up perspective transform
CATransform3D
transform =
CATransform3DIdentity
;
transform.
m34
= -
1.0
/
CAMERA_DISTANCE
;
self
.
scrollView
.
layer
.
sublayerTransform
= transform;
//create layers
for
(
int
z =
DEPTH
-
1
; z >=
0
; z--)
{
for
(
int
y =
0
; y <
HEIGHT
; y++)
{
for
(
int
x =
0
; x <
WIDTH
; x++)
{
//create layer
CALayer
*layer = [
CALayer
layer
];
layer.
frame
=
CGRectMake
(
0
,
0
,
SIZE
,
SIZE
);
layer.
position
=
CGPointMake
(x*
SPACING
, y*
SPACING
);
layer.
zPosition
= -z*
SPACING
;
//set background color
layer.
backgroundColor
=
[
UIColor
colorWithWhite
:
1
-z*(
1.0
/
DEPTH
)
alpha
:
1
].
CGColor
;
//attach to scroll view
[
self
.
scrollView
.
layer
addSublayer
:layer];
}
}
}