如何动态改变CALayer的内容
我正在创建一些 CALayers 并使用 CATransform3D 转换它们,
imageLayer.frame = CGRectMake(-22.0f, 188.0f, 180.0f, 50.0f);
imageLayer.transform = CATransform3DMakeRotation(120.0f * M_PI / 180.0f,
0.0f, 15.0f, 0.0f);
imageLayer.contents = (id)[[UIImage imageNamed:@"photo.png"] CGImage];
[caLayer addSublayer:imageLayer];
这里是一个带有输出的示例图像...
我将未转换的图像保留为图像视图,以便我可以处理滑动。我有 10 张图像的数组。因此,当用户在主图像上滑动时,相应的图像应该加载到图层和图像视图中。我可以加载图像视图,但动态加载 CALayers 时遇到一些问题。
我已经尝试过
NSArray *array=[caLayer sublayers];
caLayer = [array objectAtIndex:entryImageIndex];
//caLayer.contents=(id)[[UIImage imageNamed:@"flashImage1.jpg"] CGImage];
caLayer.contents=(id)[[UIImage imageWithCGImage:[imageArray objectAtIndex:entryImageIndex-1]]];
但这给了我错误。谁能告诉我如何用图像动态填充 CALayers...任何示例代码都会有很大帮助...
I am creating some CALayers and transforming them using CATransform3D using
imageLayer.frame = CGRectMake(-22.0f, 188.0f, 180.0f, 50.0f);
imageLayer.transform = CATransform3DMakeRotation(120.0f * M_PI / 180.0f,
0.0f, 15.0f, 0.0f);
imageLayer.contents = (id)[[UIImage imageNamed:@"photo.png"] CGImage];
[caLayer addSublayer:imageLayer];
here is an sample image with the output...
I have kept the untransformed image as image view so that i can handle swipes. I have an array of 10 images. So, when a user swipes on the main images the corresponding images should load up in the layers and image view. I can load the image view but had some problems loading the CALayers dynamically.
I have tried
NSArray *array=[caLayer sublayers];
caLayer = [array objectAtIndex:entryImageIndex];
//caLayer.contents=(id)[[UIImage imageNamed:@"flashImage1.jpg"] CGImage];
caLayer.contents=(id)[[UIImage imageWithCGImage:[imageArray objectAtIndex:entryImageIndex-1]]];
But this gave me errors. Can anyone plz tell me how to populate the CALayers dynamically with images...Any sample code will be of great help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是
尝试
或
instead of
try
or