Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如果在viewDidLoad之后添加,则CALayer不可见_Ios_Objective C_Iphone_Core Animation_Calayer - Fatal编程技术网

Ios 如果在viewDidLoad之后添加,则CALayer不可见

Ios 如果在viewDidLoad之后添加,则CALayer不可见,ios,objective-c,iphone,core-animation,calayer,Ios,Objective C,Iphone,Core Animation,Calayer,我有一个名为TiledScrollViewController的类,它与UIScrollView完全无关。在该视图控制器中,我试图通过调用newCylon将CALayer从应用程序其他位置的回调添加到视图控制器的bImageView属性中。对赛昂人。这是一个愚蠢的应用程序,但这是一个重要的问题 这就是我创建新赛昂人图层的方式 -(CALayer *)newCALayerWithNSString:(NSString *)imageName andCATransf

我有一个名为
TiledScrollViewController
的类,它与
UIScrollView
完全无关。在该视图控制器中,我试图通过调用
newCylon
将CALayer从应用程序其他位置的回调添加到视图控制器的
bImageView
属性中。对赛昂人。这是一个愚蠢的应用程序,但这是一个重要的问题

这就是我创建新赛昂人图层的方式

-(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;
}
现在。我有一个赛昂人
CALayer
,它可以显示和动画,因为我在
viewDidLoad
中调用
[self-newCylon]
。但是如果我打电话给其他任何地方的新赛昂人,什么都不会出现。我可以通过
[self.bgImageView.layer sublayers]
验证
子层
阵列的大小是否在变化。但除了第一个赛昂人,屏幕上什么也没有出现


我做错了什么?

在我的
newCylon
方法的末尾添加
[catransation flush]
修复了所有问题。

你应该根据参数的用途而不是类型来命名参数。