大佬教程收集整理的这篇文章主要介绍了iphone – 使用图层和Grand Central Dispatch渲染UIButtons的最快方法?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为了加快按钮设置,我使用Grand Central Dispatch如下.在viewDidLoad中,我使用全局队列上的dispatch_async设置每个按钮图层(向基础图层添加形状和渐变图层),以便可以在不同的线程中呈现按钮.在块的末尾,CATextLayer被添加到渐变层.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0),^{ CGRect base_bounds = CGRectMake(0,self.layer.bounds.size.width,self.layer.bounds.size.height - self.layer.bounds.size.height * 0.10f); CGPoint move_point = CGPointMake(0.0f,base_bounds.size.height * 0.10f); self.layer.masksToBounds = NO; baseLayer = [CALayer layer]; baseLayer.cornerRadius = 10.0; baseLayer.shadowOffset = CGSizeMake(0.0f,2.0f); baseLayer.shadowOpacity = 1.5f; baseLayer.shadowColor = [UIColor blackColor].CGColor; baseLayer.shadowRadius = 2.5f; baseLayer.anchorPoint = CGPointMake(0.5f,0.5f); baseLayer.position = move_point; CAShapeLayer *shape = [CALayer layer]; shape.bounds = base_bounds; shape.cornerRadius = 10.0; shape.anchorPoint = CGPointMake(0.0f,0.0f); shape.position = move_point; shape.BACkgroundColor = [UIColor darkGrayColor].CGColor; gradient = [CAGradientLayer layer]; gradient.anchorPoint = CGPointMake(0.0f,0.0f); gradient.position = CGPointMake(0.0f,0.0f); gradient.bounds = base_bounds; gradient.cornerRadius = 10.0; gradient.borderColor = [UIColor colorWithRed:0.72f green:0.72f blue:0.72f alpha:1.0].CGColor; gradient.borderWidth = 0.73; gradient.colors = [NSArray arrayWithObjects: (id)[UIColor whiteColor].CGColor,(id)[UIColor whiteColor].CGColor,nil]; [baseLayer addSublayer:shape]; [baseLayer addSublayer:gradient]; [self.layer addSublayer:baseLayer]; [textLayer setBounds:gradient.bounds]; [textLayer setPosition:CGPointMake(CGRectGetMidX(textLayer.bounds),CGRectGetMaxY(textLayer.bounds) - 6)]; [textLayer set@R_674_10495@ng:self.titleLabel.text]; [textLayer setForegroundColor:[UIColor blackColor].CGColor]; [gradient addSublayer:textLayer]; });
这种方法将总时间减少到大约2-3秒.我想知道是否有人可以建议更快的方式来渲染按钮.请注意,我对丢弃图层使用的任何解决方案都不感兴趣.
先感谢您.
以上是大佬教程为你收集整理的iphone – 使用图层和Grand Central Dispatch渲染UIButtons的最快方法?全部内容,希望文章能够帮你解决iphone – 使用图层和Grand Central Dispatch渲染UIButtons的最快方法?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。