标签: quartz-core

从CALayers获取位图,以及renderInContext的任何替代方法

我有很多CALayers在我的应用程序运行时动态创建,我需要能够生成这些的一个位图,稍后将被屏蔽.

当我需要创建蒙版时,CALayers已经被绘制到背景中(也使用了shouldRasterize = YES),并且使用renderInContext我可以获得位图.但是,随着CAlayers数量的增加,renderInContext引起的暂停变得越来越长.有没有我可以使用renderInContext的替代方法,或者我可以使用它来阻止我的应用暂时冻结?

理想情况是直接从内存/缓冲区/缓存中访问已经绘制的像素数据而不使用OpenGL,但我不确定CoreAnimation是否可以实现.

谢谢,任何其他信息都非常有用!

iphone core-animation objective-c ios quartz-core

7
推荐指数
2
解决办法
3306
查看次数

为UIView添加褪色和透明度

我知道如何制作和动画像一个在谈到与iOS新应用程序商店应用程序的共享子图的图6+(见附件截图),但我不知道如何添加漂亮的透明度着色效果在这个观点上.任何人都可以提供代码示例,使其UIView看起来与截图中的完全相同?

PS alphaUIView独有的属性不做这样的事情.

在此输入图像描述

iphone objective-c uiview ios quartz-core

7
推荐指数
2
解决办法
8475
查看次数

了解CATransform3D

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

http://cl.ly/2A2p1W1e2N3a1W181r35

这是我的"代码",但显然没有这样做.

CATransform3D _tr = CATransform3DMakeRotation(3.14/4, 1, 0, 0);
view.layer.transform = _tr;
Run Code Online (Sandbox Code Playgroud)

请帮我理解params.谢谢.

uiview catransform3d quartz-core

6
推荐指数
1
解决办法
3845
查看次数

CALayer renderInContext:导致未知崩溃

整个代码块包含以下内容:

    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,如果它与它有任何关系.该应用程序在模拟器中运行良好,但在真实设备上运行时崩溃.

iphone calayer ios quartz-core

6
推荐指数
1
解决办法
3392
查看次数

CATransform3DRotate旋转360度

我最近开始使用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)

有谁知道如何解决这个问题?提前致谢!:)

iphone objective-c calayer catransform3d quartz-core

6
推荐指数
1
解决办法
5829
查看次数

clipsToBounds和masksToBounds在分组的UITableViewCell中

我试图让我UITextView的角落被UITableViewCell包含它的分组的圆角掩盖.这是目前单元格的屏幕截图

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)

这显然不起作用,我错过了什么?

uikit cglayer ios quartz-core

6
推荐指数
1
解决办法
7524
查看次数

Xcode 14.3 以一种奇怪的方式弃用 QuartzCore API

从 Xcode 14.3 开始,Apple 弃用了 macOS 屏幕捕获的一些 API。例如:CGDisplayStream.showCursor在 macOS 13.0-13.3 中被标记为已弃用:

在此输入图像描述

然而,当我在 Xcode 14.3 中检查时,我发现这个属性是在 macOS 13 中引入的:

在此输入图像描述 我该如何理解这一点?13.0 中未引入。我从 macOS 10 开始就使用它。如果你在 Xcode 14.2 中检查相同的属性:

在此输入图像描述

这同样适用于CGDisplayStream.init和其他人。有人对此有什么想法吗?

macos xcode quartz-core

6
推荐指数
1
解决办法
292
查看次数

通过组合多个路径创建 CALayer 蒙版

我正在尝试为包含图像的 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)

calayer cashapelayer cgpath uibezierpath quartz-core

5
推荐指数
0
解决办法
3350
查看次数

CGContext线宽

我试图绘制一条简单的线,问题是它的宽度不是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)

在此输入图像描述

ios quartz-core

5
推荐指数
1
解决办法
8690
查看次数

无法将 Double 转换为预期的参数类型 CGFloat

我如何将此函数转换为 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 swift

5
推荐指数
1
解决办法
5426
查看次数