Tag: calayer

UIView的图层蒙版animation设置框架

我想创build一个UIView子类掩盖自己,以便我添加到它的任何子视图是由一个圆圈裁剪。 我想要这个视图,它是在IB中定义的子视图,以便我可以轻松地为孩子定义布局约束。 到目前为止,我有以下… @interface BubbleView () // eg: this is an example of a child view that would be "under" a mask @property(weak,nonatomic) IBOutlet UIImageView *imageView; @end @implementation BubbleView // not really sure if this kind of init is the right pattern, but it seems to work and // I don't think this is my […]

双击主页button时,延迟CALayer

当我用CALayer等影子等我的应用程序是滞后的,当我双击主页button看到任务运行。 我没有任何其他的滞后,只是当我双击。 我把这个方法调用20次放20个图像: – (UIView *)createImage:(CGFloat)posX posY:(CGFloat)posY imgName:(NSString *)imgName { UIView *myView = [[UIView alloc] init]; CALayer *sublayer = [CALayer layer]; sublayer.backgroundColor = [UIColor blueColor].CGColor; sublayer.shadowOffset = CGSizeMake(0, 3); sublayer.shadowRadius = 5.0; sublayer.shadowColor = [UIColor blackColor].CGColor; sublayer.shadowOpacity = 0.8; sublayer.frame = CGRectMake(posX, posY, 65, 65); sublayer.borderColor = [UIColor blackColor].CGColor; sublayer.borderWidth = 2.0; sublayer.cornerRadius = 10.0; […]

CABasicAnimation – 两个angular度之间的animation

我正在尝试创build一个使用CABasicAnimation的animationCALayer ,以在两个angular度之间以不连续间隔旋转的对象进行animation处理。 注意离散单词:我不是试图在两点之间创build一个连续的animation,而是我想要计算每个angular度之间的固定增量,以创build一个离散的移动感觉。 这是一张图表: 我已经考虑设置CABasicAnimation的byValue属性,但我似乎无法得到它的工作,因为你不能在一个animation中使用fromValue , ToValue ,和byValue 。 fromValue总是从零开始,所以我猜这可能会被丢弃,但是当使用当前的endAngle作为byValue和0.1的byValue (任意select,但应该用于testing)时,它仍然不会正确地animation。 任何想法如何实现这个? 这里是我正在使用的代码: anim = [CABasicAnimation animationWithKeyPath:@"currentEndAngle"]; anim.duration = 0.5f; anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; anim.toValue = [NSNumber numberWithFloat:self.endAngle]; anim.byValue = [NSNumber numberWithFloat:0.1f]; anim.repeatCount = HUGE_VALF; [anim setDelegate:self]; [self addAnimation:anim forKey:@"animKey"]; 谢谢!

在视图周围绘制阴影会减慢我的过渡,CALayer,ios

MyViewControllerB.xib包含 view( UIView ) | |__image (UIImageView) | |__view (UIView) | |__text (UITextView) | |__view (UIView) ( shadow is adding at here ) 然后我在底部的视图周围添加一个阴影如下 – (void)viewDidLoad { [super viewDidLoad]; [self.bottomView.layer setMasksToBounds:NO]; self.bottomView.layer.shadowColor = [UIColor blackColor].CGColor; self.bottomView.layer.shadowRadius = 5; self.bottomView.layer.shadowOpacity = 1; self.bottomView.layer.shadowOffset = CGSizeMake(0 , 0 ); } 当我做pushViewController: animated:在MyViewControllerA: @implementation MyViewControllerA MyViewControllerB *controller = […]

将UILabel的图层添加到另一个图层(单独的UIView)

我试图了解为什么我不能添加一个UILabel的图层作为一个单独的UIView对象的另一层的子图层。 – (void)addNumber:(NSInteger)number toLayer:(CALayer *)layer { UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))]; [numberLabel setFont:[UIFont boldSystemFontOfSize:12]]; [numberLabel setText:[NSString stringWithFormat:@"%d", number]]; /* if I change the BackgroundColor to an opaque color it renders as a solid black rect. * No matter what color I choose * Setting it as clear then it is transparent […]

禁用CALayer隐式animation

下面的类正试图阻止CALayer更改属性时发生的任何隐式animation。 // NoImplicitAnimations.h #import <Foundation/Foundation.h> #import <QuartzCore/QuartzCore.h> @interface NoImplicitAnimations : NSObject – (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key; @end // NoImplicitAnimations.m #import "NoImplicitAnimations.h" @implementation NoImplicitAnimations – (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key { return (id)[NSNull null]; } @end 我将Objective-C中的NoImplicitAnimations.h导入Swift桥接头。 我创build一个全局常量let _noImplicitAnimations = NoImplicitAnimations() 。 我这样扩展CALayer类: extension CALayer { func noImplicitAnimations () { delegate = _noImplicitAnimations } } […]

如何访问core-plot中个别栏的CALayer?

我试图在图表中的每个栏上执行一个animation,但是我不太确定如何访问每个单独的栏的图层。

RE:自动旋转,滚动,项目符号,带有属性的string缩进UIScrollView

这是一个很难做的事情,而且由于我的贡献者把它们放在一起很有帮助,公布结果似乎是公平的(下面的答案)。 如果您正在查找涉及iOS和Core Text中的属性string以及滚动的示例,则会在这里进行汇编。 几个额外的点: 包装: 这由属性string的lineBreakMode完成,默认为包装。 您将无法从string中检索软换行符(与NSTextView在string中放置'\ n'字符的Cocoa不同)。 但是你不需要。 您可以依靠Core Text的Framesetter来为您提供给定框架中的string高度,只要您将领先的信息放入属性string即可。 CATextLayer: 与它合作很方便。 所有你需要做的是分配一个属性的string,它包装和绘制。 如果你有一个简短的string显示一个选定的字体,这是伟大的。 但CATextLayer不能识别前导或缩进,所以对于这个项目我直接画到CALayer。 字体: 我坚持CTFontRef的大部分,因为它是需要在iOS中build立一个属性的string,并提供准确的领导,但有时候更容易使用UIFont。 下面是将CTFontRef( fontr )转换为UIFont的一种方法: NSString *sFontName = (NSString *)CTFontCopyName(fontr, kCTFontPostScriptNameKey); UIFont *font = [UIFont fontWithName:sFontName size:CTFontGetSize(fontr)]; CGSize sizeString = [string sizeWithFont:font]; [sFontName release]; 如果您从头开始创buildUIFont,请注意它将接受字体名称的族部分中的空格,或者可以将它们一起粉碎,但“粗体”必须用连字符分隔: self.fontTickerNormal = [UIFont fontWithName:@"Helvetica Neue" size:18.0f]; // OK self.fontTickerIndent = [UIFont fontWithName:@"HelveticaNeue" size:16.0f]; // […]

如何使convertToDeviceSpace做除了乘以一个之外的任何事情?

当我在CALayer运行这样的代码时 override open func draw(in ctx: CGContext) { let rectDEVICESPACE = ctx.convertToDeviceSpace(bounds).size print("bounds \(bounds)") print("rectDEVICESPACE \(rectDEVICESPACE)") 经过了很多很多很多分钟,我们发现不可能find任何转换或规模。 convertToDeviceSpace总是只返回相同的东西。 尝试设备,模拟器等山脉 convertToDeviceSpace除了身份之外还有什么特殊的情况呢? 这是可怕的,因为苹果文档和所有现有的代码示例使用完全相同的时候,例如,当你blitting周围找出原始像素的大小。 一个错误将是一个巨大的缺陷。 convertToDeviceSpace除了乘以1.0以外什么都可以做。 我在做什么错,特别是在testing中 – 除了身份以外,我从来没有看到任何结果?

掩盖CAShapeLayer创build这个奇怪的神器?

我想为待办事项列表创build一个平滑的进度条。 我用一个圆圈(CGMutablePath)掩盖了灰色区域,并有一个明显的圆弧状伪像。 不仅如此,酒吧右侧还有一个神器。 注:我试图栅格化图层无济于事。 什么原因导致iOS做到这一点,我该如何解决这个问题或摆脱它? private var circleMask: CAShapeLayer = CAShapeLayer() override func layoutSubviews() { super.layoutSubviews() backgroundColor = GradientColor(.leftToRight, frame: self.bounds, colors: GradientFlatRed()) layer.cornerRadius = bounds.height / 2 plainProgressBar.layer.cornerRadius = layer.cornerRadius layer.shouldRasterize = true layer.rasterizationScale = UIScreen.main.scale plainProgressBar.layer.shouldRasterize = true plainProgressBar.layer.rasterizationScale = UIScreen.main.scale createMask() } private func createMask() { let path = CGMutablePath() path.addArc(center: CGPoint(x: […]