Stronger* 2017-06-24 03:23 采纳率: 0%
浏览 534

同样的功能用swift写可以实现用oc写就不行,代码基本一致

    let lay = CAReplicatorLayer()
    lay.bounds = CGRect(x: 0, y: 0, width: 60, height: 60)
    lay.position = view.center
    lay.backgroundColor = UIColor.clear.cgColor
    view.layer.addSublayer(lay)


    let bar = CALayer()
    bar.bounds = CGRect(x: 0, y: 0, width: 8.0, height: 40.0)
    bar.position = CGPoint(x: 10, y: 75)
    bar.cornerRadius = 2.0
    bar.backgroundColor = UIColor.red.cgColor
    lay.addSublayer(bar)


    let move = CABasicAnimation(keyPath: "position.y")
    move.toValue = bar.position.y - 35.0
    move.duration = 0.5
    move.autoreverses = true
    move.repeatCount = Float.infinity
    bar.add(move, forKey: nil)
    lay.instanceCount = 3
    lay.instanceDelay = 0.33
    lay.masksToBounds = true
    lay.instanceTransform = CATransform3DMakeTranslation(10.0, 0, 0)

            以上是swift代码


             CAReplicatorLayer * lay = [CAReplicatorLayer layer];

lay.bounds = CGRectMake(0, 0, 60, 60);

lay.position = self.view.center;

lay.backgroundColor = [UIColor clearColor].CGColor;

[self.view.layer addSublayer:lay];

CALayer * bar = [CALayer layer];

bar.bounds = CGRectMake(0, 0, 8, 40);

bar.position = CGPointMake(10, 75);

bar.cornerRadius = 2.0;

bar.backgroundColor = [UIColor redColor].CGColor;

[lay addSublayer:bar];

CABasicAnimation * move = [CABasicAnimation animationWithKeyPath:@"path"];
move.fromValue = @(10);
move.toValue = @(40);
move.delegate = self;
move.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
move.toValue = [NSValue valueWithCGPoint:CGPointMake(0 ,40)];
move.duration = 0.5;
move.timingFunction = [CAMediaTimingFunction  functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//自己返回
move.autoreverses = YES;
move.repeatCount = 100;
[bar addAnimation:move forKey:@"path"];
lay.instanceCount = 3;
lay.instanceDelay = 0.33;
lay.masksToBounds = YES;
lay.instanceTransform = CATransform3DMakeTranslation(10.0, 0, 0);

以上是oc代码

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。