标签: quartz-core

将箭头附加到UIBezierPath

我需要你的帮助:

我正在尝试使用具有可变宽度的UIBezierPaths创建图形,并且包含具有两个控制点的贝塞尔曲线.现在我想在这些路径的末尾(右侧)添加箭头.有没有办法做到这一点,即通过附加一个包含三角形的较小lineWidth的子路径?这是我要添加箭头的一些路径的示例图片:

在此输入图像描述

谢谢你的帮助!

objective-c uibezierpath quartz-core

3
推荐指数
1
解决办法
1552
查看次数

属性未在drawRect方法中设置 - iOS

当我尝试访问drawRect方法中的类变量或属性时,我一直看到一些奇怪的行为.

在我的.h文件中,我有以下内容

@interface DartBoard : UIView
{
    Board * board;
    int index;
}
@property (readwrite, assign, nonatomic) NSNumber * selectedIndex;
@end
Run Code Online (Sandbox Code Playgroud)

在我的.m文件中,我有以下内容

@implementation DartBoard

@synthesize selectedIndex;

-(id)init
{
    self.selectedIndex = [NSNumber numberWithInt:5];
    index = 123;
    return self;
}

- (void)drawRect:(CGRect)rect {
    NSLog(@"selectedIndex: %d",[self.selectedIndex intValue]);
    NSLog(@"index: %d",index);
}

@end
Run Code Online (Sandbox Code Playgroud)

输出是

2012-06-12 19:48:42.579 App [3690:707] selectedIndex: 0
2012-06-12 19:48:42.580 App [3690:707] index: 0
Run Code Online (Sandbox Code Playgroud)

我一直试图找到一个解决方案,但没有运气..

我发现了类似的问题,但问题没有真正的答案

见:UIView drawRect; 类变量超出范围

我有一种感觉drawRect与普通方法不同,并没有正确地获得类的范围,但我该如何解决它?

干杯达米恩

objective-c drawrect ios quartz-core

2
推荐指数
1
解决办法
1035
查看次数

UIView带水效果

我正在制作一个基于视图的应用程序,我希望为视图提供水效果.请帮我.

我正在使用以下代码

[UIView beginAnimations:@"rippleEffect" context:NULL]; 
[UIView setAnimationDuration:1.0]; 
[UIView setAnimationTransition:(UIViewAnimationTransition)110 forView:view cache:NO]; 
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

iphone ios5 quartz-core

2
推荐指数
1
解决办法
3583
查看次数

如何快速使用贝塞尔曲线路径创建大小不同的图饼?

我想制作一个具有8个相等切片的漂亮图形饼图,可以根据一个Int或类似的东西进行单独缩放或调整大小。如下所示,只是将所有切片均等地切割:

在此处输入图片说明

我曾在Objective-C中尝试过此方法,但它仅占一小部分:

  -(CAShapeLayer *)createPieSlice {
    CAShapeLayer *slice = [CAShapeLayer layer];
    slice.fillColor = [UIColor redColor].CGColor;
    slice.strokeColor = [UIColor blackColor].CGColor;
    slice.lineWidth = 3.0;

    CGFloat angle = DEG2RAD(-60.0);
    CGPoint center = CGPointMake(100.0, 100.0);
    CGFloat radius = 100.0;

    UIBezierPath *piePath = [UIBezierPath bezierPath];
    [piePath moveToPoint:center];

    [piePath addLineToPoint:CGPointMake(center.x + radius * cosf(angle), center.y + radius * sinf(angle))];

    [piePath addArcWithCenter:center radius:radius startAngle:angle endAngle:DEG2RAD(60.0) clockwise:YES];

    //  [piePath addLineToPoint:center];
    [piePath closePath]; // this will automatically add a straight line to the center
    slice.path = piePath.CGPath;

    return slice;
    } …
Run Code Online (Sandbox Code Playgroud)

graphic ios uibezierpath quartz-core swift

2
推荐指数
1
解决办法
3853
查看次数

无法将类型'CFString'的值转换为预期的参数类型'UnsafePointer <Void>'(aka'UnsafePointer <()>')

定义行时出现构建错误

 let runFont : CTFontRef = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName)
Run Code Online (Sandbox Code Playgroud)

错误是:无法将类型“ CFString”的值转换为预期的参数类型“ UnsafePointer”(又名“ UnsafePointer <()>”)

cocoa core-text ios quartz-core swift

2
推荐指数
1
解决办法
2200
查看次数

CAShapeLayer shadowPath动画.如何防止阴影填充动画完成?

我创建一个随机UIBezierPath的路径设置为CAShapeLayer.path属性,然后在动画CAShapeLayer的行程就像这样:

    // Get a path
    let path = createBezierPath()

    // Shape layer properties
    let color = randomCGColor() // Color of path and shadow
    let lineWidth = CGFloat(arc4random_uniform(50) + 11) // Width of line and shadow radius
    shapeLayer.path = path.CGPath
    shapeLayer.lineJoin = kCALineJoinRound
    shapeLayer.lineCap = kCALineCapRound
    shapeLayer.strokeColor = color
    shapeLayer.lineWidth = lineWidth
    shapeLayer.fillColor = UIColor.clearColor().CGColor
    // Shape layer shadow properties
    shapeLayer.shadowPath = path.CGPath
    shapeLayer.shadowColor = color
    shapeLayer.shadowOffset = CGSizeZero
    shapeLayer.shadowRadius = lineWidth
    shapeLayer.shadowOpacity …
Run Code Online (Sandbox Code Playgroud)

cashapelayer caanimation quartz-core swift

2
推荐指数
1
解决办法
1245
查看次数

在 C++ 中使用 CGImageDestinationCreateWithURL 创建 CGImageDestinationRef 返回 NULL

我试图使用某些 OSX 框架中可用的方法为我的 macOS 10.13 设置的每个显示器截取屏幕截图,但使用某些 OSX 框架中的方法会返回CGImageDestinationCreateWithURL,我不知道我做错了什么。CGImageDestinationRefNULL

我认为我遇到的问题在于该行:

CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
Run Code Online (Sandbox Code Playgroud)

我正在使用的代码如下:

主要.cpp:

#include <iostream>
#include <string>
#include <QuartzCore/QuartzCore.h>
#include <CoreServices/CoreServices.h>
#include <ImageIO/ImageIO.h>

int main(int argc, const char * argv[]) {
    std::string baseImageOutput = "/Users/bogdan/Desktop";
    std::string pathSeparator = "/";
    std::string baseImageName = "image-";
    std::string imageExtension = ".png";

    CGDisplayCount displayCount;
    CGDirectDisplayID displays[32];

    // grab the active displays
    CGGetActiveDisplayList(32, displays, &displayCount);

    // go through the list
    for (int i = 0; i < …
Run Code Online (Sandbox Code Playgroud)

c++ macos core-services quartz-core

2
推荐指数
1
解决办法
837
查看次数

如何使 CAGradientLayer 跟随 CGPath

鉴于 CAShapeLayer 定义了如下图所示的路径,我想添加一个跟随形状图层路径的 CAGradientLayer。

例如,给定一个从 black->red 的渐变:

  • 右上角的圆形部分是黑色的,
  • 如果滑块是 100,左上角会是红色的,
  • 如果滑块为 50,则滑块的一半将为黑色(如下所示),可见渐变将从黑色(右上角)变为底部的红黑色

绿色应该成为渐变

我发现的每个以前的帖子实际上都没有回答这个问题。例如,因为我只能添加轴向 CAGradientLayers,所以我可以这样做(下图),但您可以看到它不正确(左上角最终再次变为黑色)。如何使渐变实际遵循路径/蒙版

在此处输入图片说明

quartz-graphics ios quartz-core swift

2
推荐指数
1
解决办法
999
查看次数

删除的线程与未提交的CATransaction不显示源?

关于:CoreAnimation: warning, deleted thread with uncommitted CATransactionmessage的堆栈溢出还有很多其他条目, 并通过启用对其进行排序CA_DEBUG_TRANSACTIONS.在我看到的99%的其他帖子中,回溯显示了未提交动画的来源(例如,参见核心动画警告:"未提交的CATransaction",其中显示了被调用的函数MyApp).

在我的情况下,我已经将CA_DEBUG_TRANSACTIONS标志设置为1并且我得到了回溯,但不幸的是它并没有告诉我它来自哪里:

Deallocating
CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0   QuartzCore                          0x00007fff95f8c76a _ZN2CA11Transaction4pushEv + 312
1   QuartzCore                          0x00007fff95f8c60a _ZN2CA11Transaction15ensure_implicitEv + 276
2   QuartzCore                          0x00007fff95f916f5 _ZN2CA5Layer13thread_flags_EPNS_11TransactionE + 37
3   QuartzCore                          0x00007fff95f91642 _ZN2CA5Layer4markEPNS_11TransactionEjj + 64
4   QuartzCore                          0x00007fff95f931df _ZN2CA5Layer25set_needs_display_in_rectERK6CGRect + 315
5   AppKit                              0x00007fff97e7ebdd _NSBackingLayerSetNeedsDisplayInRect + 319
6   QuartzCore                          0x00007fff95f93081 -[CALayer setNeedsDisplay] + 62
7   AppKit                              0x00007fff97e7ea77 -[NSView(NSInternal) _setLayerNeedsDisplayInViewRect:] + 648
8 …
Run Code Online (Sandbox Code Playgroud)

macos cocoa appkit quartz-core

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

在UIView上运行渐变不起作用

我试图以编程方式向UIView添加渐变,但它无法正常工作.它似乎根本没有颜色.我附上了相关代码以及截图.注意我应用渐变的底部正方形.有人能帮我弄清楚我在做错了什么吗?

截图

let sundayView = UIView()

override func viewDidLoad() {
    super.viewDidLoad()
    setupViews()
    setupSundayView()
}

func setupViews() {
    sundayView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(sundayView)
}

func setupSundayView() {
    sundayView.translatesAutoresizingMaskIntoConstraints = false

    NSLayoutConstraint.activateConstraints([
        sundayView.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor),
        sundayView.topAnchor.constraintEqualToAnchor(fridayView.bottomAnchor, constant: 16.0),
        sundayView.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor, constant: -8.0),            
        sundayView.heightAnchor.constraintEqualToAnchor(mondayView.heightAnchor),
        sundayView.widthAnchor.constraintEqualToAnchor(mondayView.widthAnchor)
        ])

    let gradient = CAGradientLayer()
    gradient.frame = sundayView.bounds
    gradient.colors = [
        UIColor(red:1.00, green:0.37, blue:0.23, alpha:1.0).CGColor,
        UIColor(red:1.00, green:0.16, blue:0.41, alpha:1.0).CGColor
    ]
    sundayView.layer.insertSublayer(gradient, atIndex: 0)
}
Run Code Online (Sandbox Code Playgroud)

uiview ios quartz-core cagradientlayer swift

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