我有很多CALayers在我的应用程序运行时动态创建,我需要能够生成这些的一个位图,稍后将被屏蔽.
当我需要创建蒙版时,CALayers已经被绘制到背景中(也使用了shouldRasterize = YES),并且使用renderInContext我可以获得位图.但是,随着CAlayers数量的增加,renderInContext引起的暂停变得越来越长.有没有我可以使用renderInContext的替代方法,或者我可以使用它来阻止我的应用暂时冻结?
理想情况是直接从内存/缓冲区/缓存中访问已经绘制的像素数据而不使用OpenGL,但我不确定CoreAnimation是否可以实现.
谢谢,任何其他信息都非常有用!
我知道如何制作和动画像一个在谈到与iOS新应用程序商店应用程序的共享子图的图6+(见附件截图),但我不知道如何添加漂亮的透明度着色效果在这个观点上.任何人都可以提供代码示例,使其UIView看起来与截图中的完全相同?
PS alphaUIView独有的属性不做这样的事情.

我在UIView中玩CATransform3DMakeRotation,而我正试图做45º,变换就像它倒退一样:

这是我的"代码",但显然没有这样做.
CATransform3D _tr = CATransform3DMakeRotation(3.14/4, 1, 0, 0);
view.layer.transform = _tr;
Run Code Online (Sandbox Code Playgroud)
请帮我理解params.谢谢.
整个代码块包含以下内容:
CGSize layerSize = [webview sizeThatFits:CGSizeZero];
if ([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f) {
UIGraphicsBeginImageContextWithOptions(layerSize, NO, 2.0f);
}
else {
UIGraphicsBeginImageContext(layerSize);
}
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
但经过测试,这条线是导致问题的那条线:
[webview.layer renderInContext:UIGraphicsGetCurrentContext()];
Run Code Online (Sandbox Code Playgroud)
应用程序崩溃,没有在控制台中列出任何原因,使用@try @catch @finally没有任何结果.我在AppDelegate.h中导入了Quartzcore,如果它与它有任何关系.该应用程序在模拟器中运行良好,但在真实设备上运行时崩溃.
我最近开始使用CATransform3D,看起来非常好.我只有旋转1个问题.我正在尝试将我的视图向右旋转360度,但如果我只是将360传递给CATransform3DRotate它就不起作用(它根本就不动.)
这是我的代码:
CALayer *layer = dock.layer;
CATransform3D r = CATransform3DIdentity;
r.m34 = 1.0 / -500;
r = CATransform3DRotate(r, DegreesToRadians(360.0f), 100.0f, 1.0f, 100.0f);
layer.transform = r;
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?提前致谢!:)
我试图让我UITextView的角落被UITableViewCell包含它的分组的圆角掩盖.这是目前单元格的屏幕截图

这是我用来尝试防止角落重叠我的单元格边框的一些代码.我试过了两个
cell.contentView.layer.masksToBounds = YES;
cell.layer.masksToBounds = YES; //tried this as a test, still doesn't work
detailTextView.clipsToBounds = YES;
[cell.contentView addSubview:detailTextView];
Run Code Online (Sandbox Code Playgroud)
和
cell.layer.masksToBounds = YES;
cell.contentView.layer.masksToBounds = YES;
detailTextView.clipsToBounds = YES;
[cell addSubview:detailTextView];
Run Code Online (Sandbox Code Playgroud)
这显然不起作用,我错过了什么?
我正在尝试为包含图像的 CALayer 创建蒙版。该掩码应能够使用多个路径的联合或联合的逆。就维恩图而言,这将是分离或联合否认(请在此处查看我无法发布的维恩图的图形:https : //en.wikipedia.org/wiki/Logical_connective#Common_logical_connectives)。我还在一个专门的 iOS 论坛上开始了一个线程,里面有很多图形和更多的示例代码:http : //www.raywenderlich.com/forums/viewtopic.php?f=2&t=7155
我确实成功地创建了第一个案例:多条路径的联合(分离)。
您可以将代码复制到新的单屏应用程序中进行试用(不要忘记包含 Quartz 框架):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// create a yellow background
UIView *bg = [[UIView alloc] initWithFrame:self.view.bounds];
bg.backgroundColor = [UIColor yellowColor];
[self.view addSubview:bg];
// create the layer on top of the yellow background that will be masked
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = self.view.layer.bounds;
imageLayer.backgroundColor = [[UIColor blueColor] CGColor];
// create …Run Code Online (Sandbox Code Playgroud) 我试图绘制一条简单的线,问题是它的宽度不是1像素,而是2.如果我正确读取,文档说明用户空间单位将转换为像素.
代码很简单,但我的行总是2像素宽.
//Get the CGContext from this view
CGContextRef context = UIGraphicsGetCurrentContext();
//Set the stroke (pen) color
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
//Set the width of the pen mark
CGContextSetLineWidth(context, 1);
for (int i = 1; i <= sections - 1; i++)
{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0.0, i * kSectionHeight)];
CGContextMoveToPoint(context, 0.0, i * kSectionHeight); //Start point
CGContextAddLineToPoint(context, self.frame.size.width, i * kSectionHeight);
}
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)

我如何将此函数转换为 swift?我收到一个我不明白的错误。您的班级中需要“导入 QuartzCore”。
目标C代码
void DrawGridlines(CGContextRef context, CGFloat x, CGFloat width)
{
for (CGFloat y = -48.5; y <= 48.5; y += 16.0)
{
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x + width, y);
}
CGContextSetStrokeColorWithColor(context, graphLineColor());
CGContextStrokePath(context);
}
Run Code Online (Sandbox Code Playgroud)
SWIFT代码
func DrawGridLines(context:CGContextRef, x:CGFloat, width:CGFloat)
{
for var y = -48.5; y <= 48.5; y += 16.0
{
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x + width, y);
}
//CGContextSetStrokeColorWithColor(context, graphLineColor());
//CGContextStrokePath(context);
}
Run Code Online (Sandbox Code Playgroud) quartz-core ×10
ios ×5
iphone ×4
calayer ×3
objective-c ×3
uiview ×2
cashapelayer ×1
cglayer ×1
cgpath ×1
macos ×1
swift ×1
uibezierpath ×1
uikit ×1
xcode ×1