#import "ViewController.h"
@interface ViewController ()
@property(nonatomic) CALayer *ballLayer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//创建层ballLayer对象
self.ballLayer = [CALayer layer];
//读取图片创建UIImage对象
UIImage *image = [UIImage imageNamed:@"Ball2.png"];
//设置层ballLayer对象
//设置层内容
self.ballLayer.contents = (__bridge id)(image.CGImage);
//设置层内容布局方式
self.ballLayer.contentsGravity = kCAGravityResizeAspect;
//设置层的边界
self.ballLayer.bounds = CGRectMake(0.0, 0.0, 125.0, 125.0);
//设置层的位置
self.ballLayer.position = CGPointMake(CGRectGetMidX(self.view.bounds),
CGRectGetMidY(self.view.bounds));
//添加ballLayer层到当前层
[self.view.layer addSublayer:self.ballLayer];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end