
- (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的正确方法是什么?
谢谢!
解决方法 标记,您可以使用
colorAnimation.To = Runtime.GetNSObject (UIcolor.Blue.CGcolor.Handle);
获取动画的正确对象.
Kudos到https://stackoverflow.com/users/187720/geoff-norton实际上给了我使用Runtime.GetNSObject的答案并解决了这个问题.
希望这可以帮助,
ChrisNTR
总结以上是内存溢出为你收集整理的ios – 使用Monotouch时如何将CGColor转换为NSObject?全部内容,希望文章能够帮你解决ios – 使用Monotouch时如何将CGColor转换为NSObject?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)