IOS----Core Animation介绍3
来源:互联网 发布:php快递查询源码 编辑:程序博客网 时间:2024/06/06 03:11
http://superman474.blog.163.com/blog/static/120661462011857559881/
提供layer内容
1.提供CALayer内容
(1)设置contents属性
CALayer *theLayer;
// create the layer and set the bounds and position
theLayer=[CALayer layer];
theLayer.position=CGPointMake(50.0f,50.0f);
theLayer.bounds=CGRectMake(0.0f,0.0f,100.0f,100.0f);
// set the contents property to a CGImageRef
// specified by theImage (loaded elsewhere)
theLayer.contents=theImage;
(2)使用代理去提供内容
- (void)displayLayer:(CALayer *)theLayer
{
// check the value of the layer's state key
if ([[theLayer valueForKey:@"state"] boolValue])
{
// display the yes image
theLayer.contents=[someHelperObject loadStateYesImage];
}
else {
// display the no image
theLayer.contents=[someHelperObject loadStateNoImage];
}
}
drawLayer:inContext:
下面就是一个代理实现了drawLayer:inContext:的方法:
- (void)drawLayer:(CALayer *)theLayer
inContext:(CGContextRef)theContext
{
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint(thePath,
NULL,
15.f,250.0f,
295.0f,250.0f,
295.0f,15.0f);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath );
CGContextSetLineWidth(theContext,
[[theLayer valueForKey:@"lineWidth"] floatValue]);
CGContextStrokePath(theContext);
// release the path
CFRelease(thePath);
}
- (void)display
{
// check the value of the layer's state key
if (self.state)
{
// display the yes image
self.contents=[someHelperObject loadStateYesImage];
}
else {
// display the no image
self.contents=[someHelperObject loadStateNoImage];
}
}
- (void)drawInContext:(CGContextRef)theContext
{
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint(thePath,
NULL,
15.f,250.0f,
295.0f,250.0f,
295.0f,15.0f);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath );
CGContextSetLineWidth(theContext,
self.lineWidth);
CGContextSetStrokeColorWithColor(theContext,
self.lineColor);
CGContextStrokePath(theContext);
CFRelease(thePath);
}
2.positioning layer的content。
CALayer提供一个属性contentsGravity允许我们去position and scale layer的contents image。缺省情况下,content image填充整个layer bounds。忽视自然的图像纵横比。
使用contentsGravity positioning常量去具体image的位置,如下图:
当使用positioning 常量时,contentsCenter属性将不在使用。
contentsGravity属性可以被设置为下面三种来控制其sacle。设置成下列三种时,上面的9种就失效。
- IOS----Core Animation介绍3
- IOS----Core Animation介绍3
- IOS----Core Animation介绍3
- IOS----Core Animation介绍1
- IOS----Core Animation介绍2
- IOS----Core Animation介绍4
- IOS----Core Animation介绍5
- IOS----Core Animation介绍2
- IOS----Core Animation介绍1
- IOS----Core Animation介绍2
- IOS----Core Animation介绍4
- IOS----Core Animation介绍5
- iOS开发有关Core Animation的介绍
- Core Animation介绍1
- Core Animation基础介绍
- Core Animation基础介绍
- iOS-Core-Animation-Advanced-Techniques(七-3)
- IOS开发—Core Animation核心动画介绍
- 素食的好处
- diff比较两个目录时,如何略过特定目录或文件
- IOS----Core Animation介绍1
- 教你配置浏览器的苹果绿背景-保护您的眼睛
- IOS----Core Animation介绍2
- IOS----Core Animation介绍3
- $inc计数器
- IOS----Core Animation介绍4
- EDBC居然被顶到Hacker News的首页!
- IOS----Core Animation介绍5
- VC6的watch窗口的一些小技巧
- 浅谈程序员创业
- Linux chmod命令详解
- javascript与MFC ActiveX控件接口方法数据交换