Tag: calayer

将CIFilter应用于CALayer

所以, CIfilter现在可以在iOS 5中使用,而且我正试图将一个应用到CALayer上, 就像在Mac上一样 。 这是我的代码: CALayer *myCircle = [CALayer layer]; myCircle.bounds = CGRectMake(0,0,30,30); myCircle.position = CGPointMake(100,100); myCircle.cornerRadius = 15; myCircle.borderColor = [UIColor whiteColor].CGColor; myCircle.borderWidth = 2; myCircle.backgroundColor = [UIColor whiteColor].CGColor; CIFilter *blurFilter = [CIFilter filterWithName:@"CIDiscBlur"]; [blurFilter setDefaults]; [blurFilter setValue:[NSNumber numberWithFloat:5.0f] forKey:@"inputRadius"]; [myCircle setFilters:[NSArray arrayWithObjects:blurFilter, nil]]; [self.view.layer addSublayer:myCircle]; 我的白色圆圈画得很好,但没有应用filter。 有什么想法吗?

如何在UIViewanimation过程中animationUIView图层的子图层?

在视图的UIViewanimation中,通过在[UIView animateWithDuration:delay:options:animations:completion:]的options参数中包含UIViewAnimationOptionLayoutSubviews ,可以为其子视图设置[UIView animateWithDuration:delay:options:animations:completion:] 。 然而,当我们不是某个视图的背景层的时候,我找不到一个方法来为它的子层设置animation。 他们只是跳到适当的位置,以配合视图的新界限。 由于我正在使用图层而不是视图,看起来像我不得不使用核心animation而不是UIViewanimation,但我不知道如何(和何时)做到这一点,使图层animation将匹配视图animation。 这是我的基本问题。 如果你想知道我想要完成的具体事情,请阅读更多内容。 我已经创build了一个带有虚线边框的视图,在视图的图层中添加了一个CAShapeLayer(参见这个stackoverflow问题: UIView周围的虚线边框 )。 我调整了CAShapeLayer的path以匹配layoutSubviews视图的边界。 这个工作,但有一个化妆品的问题:当视图的边界animation在一个UIViewanimation(如在旋转期间),虚线边框跳转到视图的新边界,而不是平滑的animation,因为视图animation的边界。 也就是说,当视图animation时,虚线边框的右侧和底部不分别保持与视图的右侧和底部部分相邻。 我怎样才能从CAShapeLayer的虚线边界animation的边界animation的视图旁边? 我到目前为止所做的是将一个CABasicAnimation附加到CAShapeLayer上: – (void)layoutSubviews { [super layoutSubviews]; self.borderLayer.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath; self.borderLayer.frame = self.bounds; CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; [self.borderLayer addAnimation:pathAnimation forKey:nil]; } 这确实会使虚线边框生成animation,但它没有正确的计时function和animation持续时间以匹配视图animation。 另外,有时候,我们不希望虚线边框动起来,就像当视图第一次布局时,边框不应该从一些旧pathanimation到新的正确path; 它应该只是出现。

animationAVPlayerLayer videoGravity属性

我试图在video播放中复制苹果的行为,允许用户伸展video图像来填充边界。 @interface FHVideoPlayerView : UIView @end @interface FHVideoPlayerView + (Class)layerClass { return [AVPlayerLayer class]; } – (void)setAspectMode:(FHVideoPlayerAspectMode)aspectMode animated:(BOOL)animated { FHVideoPlayerAspectMode current = [self aspectMode]; FHVideoPlayerAspectMode final = aspectMode; NSString *fromValue; NSString *toValue; AVPlayerLayer *layer = (AVPlayerLayer *)[self layer]; switch (current) { case FHVideoPlayerAspectFill: fromValue = AVLayerVideoGravityResizeAspectFill; break; case FHVideoPlayerAspectFit: fromValue = AVLayerVideoGravityResizeAspect; break; default: break; […]

在iOS中使用混合模式堆叠UIViews

我有两个不同的UIImageViews 。 我想使顶部UIImageView混合使用屏幕混合模式与底部UIImageView 。 我知道CALayer的属性: compositingFilter ,我知道它不适用于iOS。 我已经search了很多的解决scheme,我已经find了如何UIView并覆盖drawRect 。 我试图将drawRect的上下文设置为屏幕混合模式,尽pipe它仍然正常绘制每一个图像。 也许我做错了什么,或者做法不一样。 也许我需要OpenGL或CALayer来实现这一点。 有人可以帮忙吗?

CALayer的抗混叠对angular线边缘

当我使用CATransform3DRotate设置我的CALayer的transform属性时,图层被正确旋转。 但是,图层的边缘是锯齿状的,而不是反锯齿的。 我已经阅读了关于这个主题的几个post: iPhone:CALayer +旋转3D +抗锯齿? iPhone – 在将视angular应用于CALayer时变得粗糙 我试图通过在我的对angular线图层上设置以下属性来纳入他们的build议 CALayer* layer = myView.layer; layer.shadowOpacity = 0.01; layer.edgeAntialiasingMask = kCALayerTopEdge | kCALayerBottomEdge | kCALayerRightEdge | kCALayerLeftEdge; layer.borderWidth = 1.0; layer.borderColor = [UIColor clearColor].CGColor; layer.backgroundColor = [UIColor greenColor].CGColor; 我也重写了我的对angular层的drawLayer:inContext:方法来确保抗锯齿: -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context { CGContextSetAllowsAntialiasing(context, true); CGContextSetShouldAntialias(context, true); CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor); CGContextFillRect(context, self.bounds); } 我错过了什么?

iOS核心animation:CALayer bringSublayerToFront?

如何将CALayer sublayer带到所有子图层的前面,类似于-[UIView bringSubviewToFront] ?

iOS CAlayer方向AVCaptureVideoPreviewLayer不旋转

总结:我不能强迫CALayer正确地响应方位变化。 每当我尝试使用cgaffinetransform我越来越奇怪的结果(图层不居中)。 任何帮助将不胜感激! 谢谢, 过程我使用AVCaptureVideoPreviewLayer子类添加video预览。 当设备处于纵向时,一切看起来都很好。 设备旋转到横向(左侧或右侧)或纵向颠倒时出现问题。 我使用AVCaptureVideoPreviewLayer子类添加video预览。 当设备处于纵向时,一切看起来都很好。 设备旋转到横向(左侧或右侧)或纵向颠倒时出现问题。 我使用以下代码添加预览图层: CGRect layerRect = [[[self view] layer] bounds]; [[[self captureManager] previewLayer] setBounds:layerRect]; [[[self captureManager] previewLayer]setFrame:CGRectMake(0, height, width, height)]; [[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))]; 并且在纵向模式下正确显示。 当我尝试旋转设备时,预览图层performance奇怪。 它似乎不会调整自身,它不正确旋转。 我试图通过添加下面的方法来解决它 -(void)rotateLayer{ CALayer * stuckview = [[self captureManager] previewLayer]; CGRect layerRect = [[[self view] layer] bounds]; UIDeviceOrientation orientation =[[UIDevice currentDevice]orientation]; […]

向uiview的右下方投下阴影

我必须在uiview的右下angular放一个阴影,我在界面制作器中做了这个。但是我看到阴影落在了它的上面。不同的尺寸,但是不能得到它。 layer.masksToBound=No layer.shadowOpacity=0.15 layer.shadowRadius=2 layer.shadowOffSet={10,-10} //Values being set in Interfacebuilder. 尽pipe如此,这还是让阴影笼罩在顶部。我该怎么做才能看到底部。

animation期间无法获取CALayer的当前位置

我试图实现一个animation,当你按下一个button时,它将animation块放下,当你释放时,它将animation恢复到原来的位置,但无论如何我都无法获得animation块的当前位置。 这是我的代码: -(IBAction)moveDown:(id)sender{ CGRect position = [[container.layer presentationLayer] frame]; [movePath moveToPoint:CGPointMake(container.frame.origin.x, position.y)]; [movePath addLineToPoint:CGPointMake(container.frame.origin.x, 310)]; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; moveAnim.path = movePath.CGPath; moveAnim.removedOnCompletion = NO; moveAnim.fillMode = kCAFillModeForwards; CAAnimationGroup *animGroup = [CAAnimationGroup animation]; animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil]; animGroup.duration = 2.0; animGroup.removedOnCompletion = NO; animGroup.fillMode = kCAFillModeForwards; [container.layer addAnimation:animGroup forKey:nil]; } -(IBAction)moveUp:(id)sender{ CGRect position […]

核心animationCALayer掩盖animationperformance

我们想在我们的iPhone应用程序中使用UITabBar,但有一个例外:我们有一个“同步”button,我想在同步操作发生时旋转。 不幸的是,这意味着必须创build一个自定义选项卡栏,但这不是在这里,也不在那里:我使用Core Animation实现的animation看起来很棒。 问题是,虽然animation,它会影响其他一切在屏幕上使用animation的性能:UITableView滚动,MKMapView平移和引脚滴等我的testing设备是iPhone 4。 这个问题似乎是我已经实现了标签栏 – 我想实现与UITabBar非常相似的地方,在那里你只需要为图标提供一个PNG,并且它使用alpha通道来创build正常的和突出显示的状态,通过屏蔽背景图片。 我用CALayer的mask属性完成了这个工作: // Inside a UIView subclass' init method… // Create the mask layer by settings its contents as our PNG icon. CALayer *maskLayer = [CALayer layer]; maskLayer.frame = CGRectMake(0, 0, 31, 31); maskLayer.contentsGravity = kCAGravityCenter; maskLayer.contentsScale = [[UIScreen mainScreen] scale]; maskLayer.rasterizationScale = [[UIScreen mainScreen] scale]; maskLayer.contents = […]