Tag: calayer

蒙面UIView,CALayer的animation

我试图达到以下目的:用户点击一个视图,一个圆形视图popup到它的左侧,其中的一些图像内容。 该视图应该从触摸点开始到在触摸视图之外的最后一帧开始animation。 在animation中,它应该是一个圆圈,成长到正确的位置和大小 下面的代码都可以正常工作,只有在animation过程中 ,圆形边界只在左边。 这就像CALayer形状正在滑入其最终框架。 看起来有点像这样 一旦animation完成,我就有预期的整个圆。 CGFloat w = 300; CGRect frame = CGRectMake(myX, myY, w, w); CGPoint p = [touch locationInView:self.imageView]; CGRect initialFrame = CGRectMake(px, py, 0,0); UIImageView *circle = [[UIImageView alloc] initWithFrame:frame]; circle.image = [UIImage imageNamed:@"china"]; circle.contentMode = UIViewContentModeScaleAspectFill; circle.backgroundColor = [UIColor clearColor]; circle.layer.borderWidth = 1; circle.layer.borderColor = [UIColor grayColor].CGColor; circle.layer.masksToBounds […]

UIViewanimation块暂停animation和完成代码

我有一个animation块来执行一个简单的转换为基础的animation,完成后从其超视图中删除有问题的视图。 UIView *msgView = [[UIView alloc] initWithFrame:CGRectMake(160, 120, 160, 100)]; // Do stuff to set up the subviews of msgView. // Add the msgView to the superview (ViewController) that is going to display it. CATransform3D transform = CATransform3DMakeScale(2.5, 2.5, 1.0); [UIView animateWithDuration:5.0 animations:^(void){msgView.layer.transform = transform;} completion:^(BOOL finished){[msgView removeFromSuperview];}]; 然后,我使用http://developer.apple.com/library/ios/#qa/qa1673/_index.html中详细介绍的代码来暂停animation。 -(void)pauseLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer […]

CALayer – 放置在storyboard UIButton下面的子图层?

我有几个UIButtons在我的故事板中有一个视图控制器。 其中一个激活一个显示在子图层中的AVFoundation相机预览图层: captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; captureVideoPreviewLayer.frame = self.view.bounds; [self.view.layer addSublayer:captureVideoPreviewLayer]; 这个工作正常,除了预览层被渲染在我的button之上,所以即使button仍然是可点击的,它们不能被用户看到。 有一个简单的方法来放置button下面的子图层? 或者一个简单的方法来提升图层中的button? 非常感谢!

Swift 3:如何创buildUIImageView的边缘/边angular模糊?

目前我有一个CALayer应用于UIImageView像这样: let l: CALayer = imageView.layer l.masksToBounds = true l.cornerRadius = 20.0 我想要达到如下所示的模糊效果: 我已经尝试了以下内容: let blurEffect = UIBlurEffect(style: .light) let visualEffectView = UIVisualEffectView(effect: blurEffect) imageView.addSubview(visualEffectView) 以及: var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light)) visualEffectView.frame = staffImageView.bounds imageView.addSubview(visualEffectView) 但是,两者都没有达到我想要的结果。 有人可以提供帮助吗? 这似乎很简单,但我无法实现。 更新:我试图玩渐变,但没有太多的运气: var maskLayer = CAGradientLayer() maskLayer.frame = cell.imageView.bounds let black = UIColor.white.cgColor let clear = UIColor(white: […]

iOS:抗锯齿失败(CALayer中的PNG)

我试图在屏幕上绘制这个图像: 这是代码: CALayer* dullLayer = [CALayer layer]; { dullLayer.frame = CGRectMake(0,0,BUTTON_SIZE,BUTTON_SIZE); dullLayer.position = CGPointFromPoint2D( btnCenter ); dullLayer.opacity = topQuadrant ? 1.0 : 0.5; [wheelLayer addSublayer: dullLayer]; } UIImage* test = [UIImage imageNamed: @"OuterButton_Dull.png"]; dullLayer.contents = (id) [test CGImage]; 这是我得到的: 是什么赋予了? 为什么边缘如此锯齿? 将其与用完全相同的方式合成的罗马数字图像进行对比。 我努力了 dullLayer.edgeAntialiasingMask = 0x0f; // binary 1111 无济于事。 编辑: http : //lists.apple.com/archives/cocoa-dev/2008/Feb/msg02070.html

如何在隐式animationanimationCALayer的同时inheritanceanimation属性

我正在尝试使用隐式animation在CALayer上设置一个自定义属性: [UIView animateWithDuration:2.0f animations:^{ self.imageView.myLayer.myProperty = 1; }]; In -actionForKey:方法我需要返回animation来处理插值。 当然,我必须告诉animation如何检索animation的其他参数(即持续时间和定时function )。 – (id<CAAction>)actionForKey:(NSString *)event { if ([event isEqualToString:@"myProperty"]) { CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"myProperty"]; [anim setFromValue:@(self.myProperty)]; [anim setKeyPath:@"myProperty"]; return anim; } return [super actionForKey:event]; } } 任何想法如何实现呢? 我试图在图层属性中寻找animation,但找不到任何有趣的东西。 由于actionForKey:在animation之外被调用,所以我还有一个animation层的问题。

反转基于笔划的CALayer掩码(不填充)

亲爱的堆栈溢出社区, 我在iOS(Swift)中有一个关于CAShapeLayer的mask属性的问题。 我试图实现的是一个橡皮擦 ,通过掩盖它来擦除部分图像层。 问题出现了,当我尝试颠倒它。 我发现了一些反转path的好方法,但是这些只在使用填充path时才有用。 我想要做的就是画出一条path,用倒置的方式来掩盖图像。 笔画上的线条宽度应该在30.0左右,看起来像橡皮擦。 我尝试了不同的事情。 我目前的版本是这样的: 创build一个包含橡皮擦笔划path的CAShapeLayer 设置图层的fill-color nil 设置stroke-color和line width 添加图层作为图像层的蒙版 这工作正常,但它只是使图像的部分可见,在中风 。 我想扭转它。 我想到了一个黑色和白色的面具,但这是行不通的,因为面具是通过alpha通道传递的。 有没有人有一个想法如何解决这个问题?

AVCaptureVideoPreviewLayer横向

如何获得“AVCaptureVideoPreviewLayer”以横向显示正确显示? 它在纵向上工作正常,但不旋转,并且在父视图控制器处于横向方向时显示旋转的相机捕捉。

确定一个CALayer旋转了多less

我有一个CALayer必须旋转到一定值的程序。 我如何确定一个CALayer的当前旋转? 我有一个旋转图层的UIRotationGestureRecognizer: – (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer == rotationGestureRecognizer) { NSLog(@"gestureRecRotation: %f", rotationGestureRecognizer.rotation); CATransform3D current = _baseLayer.transform; _baseLayer.transform = CATransform3DRotate(current, rotationGestureRecognizer.rotation * M_PI / 180, 0, 0, 1.0); } } 我从一个图层开始,必须旋转一定的数量来适应一个难题。 那么如何获得图层的当前旋转呢?

在iOS上,setNeedsDisplay真的不会导致drawRect被调用…除非CALayer的显示或drawInContext终于调用drawRect?

我不太了解CALayer的display和drawInContext如何与视图中的drawRect相关联。 如果我有一个每隔1秒设置[self.view setNeedsDisplay]的NSTimer,那么drawRect每1秒调用一次,如drawRect的NSLog语句所示。 但是,如果我inheritance一个CALayer并将其用于视图,如果我使display方法为空,那么现在drawRect永远不会被调用。 更新:但display每1秒调用一次,如NSLog语句所示。 如果我删除那个空的display方法并添加一个空的drawInContext方法, drawRect再也不会被调用。 更新:但是drawInContext每隔1秒调用一次,如NSLog语句所示。 究竟发生了什么? 看起来display可以select性地调用drawInContext , drawInContext可以select性地调用drawRect (怎么样?),但是这里的真实情况是什么? 更新:有更多的线索回答: 我将CoolLayer.m代码更改为以下内容: -(void) display { NSLog(@"In CoolLayer's display method"); [super display]; } -(void) drawInContext:(CGContextRef)ctx { NSLog(@"In CoolLayer's drawInContext method"); [super drawInContext:ctx]; } 所以,如果在视图中的位置(100,100)处有一个月亮(如Core Graphics绘制的圆圈),现在我将其更改为位置(200,200),自然,我将调用[self.view setNeedsDisplay] ,现在,CALayer将根本没有caching新的视图图像,因为我的drawRect指出现在应该如何显示月亮。 即使如此,入口点是CALayer的display ,然后CALayer的drawInContext :如果我在drawRect设置一个断点,调用堆栈显示: 所以我们可以看到CoolLayer的display先input,然后进入CALayer的display ,然后是CoolLayer的drawInContext ,然后是CALayer的drawInContext ,即使在这种情况下,新图像也不存在这样的caching。 最后,CALayer的drawInContext调用委托的drawLayer:InContext 。 委托是视图( drawLayer:InContext或UIView)…和drawLayer:InContext是UIView中的默认实现(因为我没有覆盖它)。 最后是drawLayer:InContext调用drawRect 。 所以我猜两点:为什么它进入CALayer即使没有caching的图像? 因为通过这种机制,图像被绘制在上下文中,最后返回display ,CGImage从这个上下文创build,然后它被设置为新的图像caching。 […]