【发布时间】:2015-02-16 08:14:58
【问题描述】:
我有一个名为TiledScrollViewController 的类,它与UIScrollView 一点关系都没有。在该视图控制器中,我试图通过调用newCylon,从应用程序其他地方的回调将CALayer 添加到我的视图控制器上的bgImageView 属性。是的。赛昂。这是一个愚蠢的应用程序,但这是一个重要的问题。
这就是我创建新 cylon 层的方式。
-(CALayer *)newCALayerWithNSString:(NSString *)imageName
andCATransform3D:(CATransform3D)transform
andCGPoint:(CGPoint)point {
CALayer *outputLayer = [CALayer layer];
UIImage *img = [UIImage imageNamed:imageName];
outputLayer.backgroundColor = [UIColor colorWithPatternImage:img].CGColor;
[outputLayer setBounds:CGRectMake(0.0, 0.0, img.size.width, img.size.height)];
outputLayer.transform = transform;
[outputLayer setPosition:point];
[outputLayer setZPosition:5.0];
return outputLayer;
}
这就是我在newCylon 中的称呼。
-(CALayer *)newCylon{
NSLog(@"NEW CYLON");
CALayer *cylon = [self newCALayerWithNSString:@"Cylon"
andCATransform3D:CATransform3DMakeScale(.3, -.3, .3)
andCGPoint:CGPointMake(.5*screenWidth,0)];
[self.bgImageView.layer addSublayer:cylon]; // this works, but I don't see anything
[self moveCylon:cylon];
return cylon;
}
现在。我有一个 cylon CALayer,它显示和动画,因为我在 viewDidLoad 内部调用 [self newCylon]。但是,如果我在其他任何地方打电话给newCylon,什么都不会出现。我可以通过[self.bgImageView.layer sublayers] 验证sublayers 数组的大小正在发生变化。但除了第一个赛昂之外,屏幕上什么也没有出现。
我做错了什么?
【问题讨论】:
-
你应该为你的参数命名它们的用途,而不是它们的类型。
标签: ios objective-c iphone core-animation calayer