大佬教程收集整理的这篇文章主要介绍了ios – 使用Monotouch时如何将CGColor转换为NSObject?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)viewDidLoad { [super viewDidLoad]; // Create the path thisPath = CGPathCreateMutable(); CGPathMoveToPoint(thisPath,NULL,100.0f,50.0f); CGPathAddLineToPoint(thisPath,10.0f,140.0f); CGPathAddLineToPoint(thisPath,180.0f,140.0f); CGPathCloseSubpath(thisPath); // Create shape layer shapeLayer = [CAShapeLayer layer]; shapeLayer.frame = self.view.bounds; shapeLayer.path = thisPath; shapeLayer.fillColor = [UIColor redColor].CGColor; [self.view.layer addSublayer:shapeLayer]; // Add the animation CABasicAnimation* colorAnimation = [CABasicAnimation animationWithKeyPath:@"fillColor"]; colorAnimation.duration = 4.0; colorAnimation.repeatCount = 1e100f; colorAnimation.autoreverses = YES; colorAnimation.fromValue = (id) [UIColor redColor].CGColor; colorAnimation.toValue = (id) [UIColor blueColor].CGColor; [shapeLayer addAnimation:colorAnimation forKey:@"animateColor"]; }
这会按预期动画颜色偏移.当我把它移植到Monotouch时,我试过:
public override void ViewDidLoad () { base.ViewDidLoad (); thisPath = new CGPath(); thisPath.MoveToPoint(100,50); thisPath.AddLineToPoint(10,140); thisPath.AddLineToPoint(180,140); thisPath.CloseSubpath(); shapeLayer = new CAShapeLayer(); shapeLayer.Path = thisPath; shapeLayer.FillColor = UIColor.Red.CGColor; View.Layer.AddSublayer(shapeLayer); CABasicAnimation colorAnimation = CABasicAnimation.FromKeyPath("fillColor"); colorAnimation.Duration = 4; colorAnimation.RepeatCount = float.PositiveInfinity; colorAnimation.AutoReverses = true; colorAnimation.From = NSObject.FromObject(UIColor.Red.CGColor); colorAnimation.To = NSObject.FromObject(UIColor.blue.CGColor); shapeLayer.AddAnimation(colorAnimation,"animateColor"); }
但动画永远不会播放. animationStarted事件确实被提升,因此可能是它试图运行动画,但我没有在屏幕上看到任何可见的证据.
我已经玩了一天中的大部分时间,我认为这是从CGColor转换为NSObject – 我尝试过NSObject.FromObject,NSValue.ValueFromHandle等,但是还没有找到任何方法来获取动画以正确拾取开始和结束值.
为动画提供CGColor作为NSObject的正确方法是什么?
谢谢!
以上是大佬教程为你收集整理的ios – 使用Monotouch时如何将CGColor转换为NSObject?全部内容,希望文章能够帮你解决ios – 使用Monotouch时如何将CGColor转换为NSObject?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。