Tag: calayer

在UIImageView上加上0.3不透明的黑色覆盖

我有一个UIImageView,我想在它上面添加一个黑色的覆盖。 这样做的最好方法是什么,而不必重写drawRect? 我正在考虑在其上添加一个CALayer。 但不确定如何获得一个.3阿尔法的黑色CALayer。

需要更好,更简单地了解CATransform3D

请通过图像。 所以这是我从一些在线来源获得的代码,它改变了我的对象。 除此之外,我什么也不懂。 我是CATransform3D的新手,想知道它是如何工作的。 CATransform3D transform = CATransform3DIdentity; transform.m34 = 1.0 / -500; transform = CATransform3DRotate(transform, 45.0f * M_PI / 180.0f, 0, 1, 0.0f); _bgView.layer.transform = transform; 我想知道这个代码是如何运行的? 为什么我们在m34中设定一些价值? 我发现它的某种matrix更令我困惑。 另外, CATransform3DRotate中的参数是什么意思? 我想了解,但没有进一步。 我想深入了解CATransform3D。 请帮助任何文章,文件或解释自己。 非常感谢。

自定义视图与CALayer的有线效果,当animation边界改变

我已经实现了添加CALayer作为UIView子层的自定义视图。 当我使用下面的animation视图: UIView.animateWithDuration(2.0) { self.slider.bounds.size *= 2.0} ,缩放animation是错误的。 CALayer从错误的位置开始缩放尺寸,移动到最终位置,而不是缩放视图。 CustomeView代码: import UIKit class GridMaskView: UIView { private let cornerLayer: CAShapeLayer private let borderLayer: CAShapeLayer private let gridLayer: CAShapeLayer private let gridSize: (horizontal: UInt, vertical: UInt) = (3, 3) private let cornerThickness: CGFloat = 3.0 private let cornerLength: CGFloat = 20.0 private let borderThickness: CGFloat = […]

无法在视图图层中捕捉遮罩

所以我使用下面的代码将图像蒙版应用于UIView图层: CALayer *maskLayer = [CALayer layer]; UIImage *maskImage = self.image.image; maskLayer.contents = (id)maskImage.CGImage; maskLayer.frame = CGRectMake(0.0, 0.0,1235, 935); self.bgView.layer.mask = maskLayer; 一切都很好,戴着面具覆盖了视图的内容和作品。 不过,我正在尝试截图让用户保存图像。 我使用下面的代码: UIGraphicsBeginImageContext(captureFrame.size); [self.bgView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 框架是好的,并保存到照片库。 唯一的问题是应用于图层的蒙版不能在JPG中显示。 我也尝试嵌套我的bgView到另一个UIView,然后尝试renderInContext:但它是同样的事情。 它看起来好像在最后的JPG中没有应用蒙版。 有任何想法吗? 谢谢。

当在animation中调用块时停止填充颜色animation闪烁

我无法弄清楚为什么我的animation块完成后,animation从fromValue闪烁到toValue。 我知道在完成一个animation之后,您必须将CALayer的值设置为animation的结束状态,以保持animation的一致性。 然而,无论我把这些方法称为什么顺序,我总是得到闪烁的结果。 我正在做的是用biezerpath画一个复选标记,然后一旦strokeEndanimation完成,我通过animationfillColor属性填充复选标记。 填充复选标记function和复位复选标记function都是在用户选中与checkmark关联的tableviewcell的行时触发的。 噢,我正在使用AutoLayout,如果这有所作为。 所以我想知道一些事情实际上是一个1)一旦表格视图单元格被显示,我调用公共函数shoudSetCheckmarkToCheckedState设置布尔self.userSelectedCheckmark参数在函数中传递的isChecked。 从那里我调用[self setNeedsLayout],它触发layoutSubviews并调用shouldDrawCheckmark …函数。 我这样做的原因是因为如果我不第一次绘制单元格,就没有框架设置,所以我的绘图看起来很乱。 所以我应该每次我改变userSelectedCheckmark属性或者有更好的方法调用setNeedsLayout。 2)一旦animation完成,为什么复选标记闪烁。 我想我知道为什么,因为当animation完成时,图层属性被重置为与图层开始animation时相同的状态。 那么我该如何解决这个问题? 我只是触发一个计时器来改变animation结束前一毫秒的填充颜色,但是这并不正确。 inheritance人的代码btw typedef void (^animationCompletionBlock)(void); #define kAnimationCompletionBlock @"animationCompletionBlock" #import "CheckmarkView.h" #import "UIColor+HexString.h" @interface CheckmarkView() @property (nonatomic,strong) CAShapeLayer *checkmarkLayer; @property (nonatomic,assign) BOOL userSelectedCheckmark; – (void)shouldDrawCheckmarkToLayerWithAnimation:(BOOL)animateCheckmark; @end @implementation CheckmarkView #pragma mark – Lifecycle /**********************/ – (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) […]

将圆angular添加到只有UITableView的顶部?

我想添加圆angular只有我的UITableView的顶部angular落,但问题是,与下面的代码,它只是在我的整个UITableView黑色层。 我将如何解决这个问题? //Rounded Corners for top corners of UITableView UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(10.0, 10.0)]; UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = thetableView.bounds; maskLayer.path = maskPath.CGPath; CAShapeLayer *maskLayer2 = [CAShapeLayer layer]; maskLayer.frame = thetableView.bounds; maskLayer.path = […]

在向后播放CABasicAnimation后,CALayer消失

我有一个CALayer,我已经添加了一个CABasicAnimation像这样: circle = CALayer() circle.frame = CGRect(x: 0, y: 0, width: 100, height: 100) circle.backgroundColor = UIColor.green().cgColor circle.cornerRadius = 50 circle.speed = 0 view.layer.addSublayer(circle) animation = CABasicAnimation(keyPath: "position") animation.duration = 1 animation.fromValue = NSValue(cgPoint: CGPoint(x: 50, y: 50)) animation.toValue = NSValue(cgPoint: CGPoint(x: view.bounds.width / 2, y: view.bounds.height / 2)) animation.fillMode = kCAFillModeBoth animation.isRemovedOnCompletion = false […]

由于未捕获exception'CALayerInvalidGeometry',原因:'CALayer界限包含NaN:'

我正在开发一个图书应用程序,用户可以在TextView上更改字体大小。 当用户更改字体大小时,应用程序保存当前文本位置不会在用户更改字体大小后更改。 它在大多数情况下工作正常,但有时,当用户更改字体大小,应用程序得到这种错误,我仍然不能告诉如何解决这个问题。 由于未捕获exception'CALayerInvalidGeometry',原因:'CALayer界限包含NaN:[0 nan; 280 524]” *第一掷调用堆栈:(0x3231e3e7 0x3a019963 0x3231e307 0x33edb4d7 0x33edb30d 0x3419141f 0x3419b82f 0x342d1cf1 0x3414f80d 0xe7bf1 0xe607d 0xfad35 0x34218087 0x34218111 0x34218087 0x3421803b 0x34218015 0x342178cb 0x34217db9 0x341405f9 0x3412d8e1 0x3412d1ef 0x35e455f7 0x35e45227 0x322f33e7 0x322f338b 0x322f220f 0x3226523d 0x322650c9 0x35e4433b 0x341812b9 0xdf9f1 0xdf978)的libc ++ ABI。 dylib:terminate调用抛出exception 由于偶尔出现这个问题,我也无法100%重现这个问题。 这是代码。 有没有人有一个想法来解决这个问题? 提前致谢。 – (UITextRange *)getCurrentTextRange:(UITextView *)textView { CGRect bounds = […]

iOS:我应该为animation添加UIViews还是CALayers?

比方说,我想添加50个图像到一个视图为animation他们的目的。 假设我正在计划使用Core Animation(例如CABasicAnimation)而不是“UIView”animation。 我最好join50个子视图还是50个子图层? 这有什么不同吗? 谢谢。

是否可以在UIProgressView中添加多个颜色?

基本上,我想要创build一个自定义的progressview,根据进度值将有不同的颜色。 它应该如下所示: [—–红色—-] [ – 黄色 – ] [ – 绿色 – ]