【发布时间】:2012-09-27 04:56:33
【问题描述】:
- (void)drawRect:(CGRect)rect{
float sliceSize = rect.size.width / imagesShownAtOnce;
//Apply our clipping region and fill it with black
[clippingRegion addClip];
[clippingRegion fill];
//Draw the 3 images (+1 for inbetween), with our scroll amount.
CGPoint loc;
for (int i=0;i<imagesShownAtOnce+1;i++){
loc = CGPointMake(rect.origin.x+(i*sliceSize)-imageScroll, rect.origin.y);
[[buttonImages objectAtIndex:i] drawAtPoint:loc];
}
//Draw the text region background
[[UIColor blackColor] setFill];
[textRegion fillWithBlendMode:kCGBlendModeNormal alpha:0.4f];
//Draw the actual text.
CGRect textRectangle = CGRectMake(rect.origin.x+16,rect.origin.y+rect.size.height*4/5.6,rect.size.width/1.5,rect.size.height/3);
[[UIColor whiteColor] setFill];
[buttonText drawInRect:textRectangle withFont:[UIFont fontWithName:@"Avenir-HeavyOblique" size:22]];
}
clippingRegion 和 textRegion 是 UIBezierPaths 给我我想要的圆角矩形(第一个是剪切区域,第二个是我的文本的覆盖)
中间部分是绘制 3 张图像并让它们滚动,我会从 CADisplayLink 中每 2 次刷新更新一次,这会通过调用 [self setNeedsDisplay] 使绘制区域无效,并增加我的 imageScroll 变量。
现在背景信息已经完成,这是我的问题:
它运行,甚至运行平稳。但它消耗了绝对大量的 CPU 时间(80%+)!!我如何将它推到手机上的 GPU 上?有人告诉我 CALayers,但我以前从未处理过它们
【问题讨论】:
标签: objective-c ios core-animation core-graphics