老虎机应用程序还有其他方法吗?这是因为UIPICKER方法没有缓慢的动画效果。
发布于 2012-03-21 17:57:46
这可以使用CALayer动画来完成。
您的主slotMachineView层的类需要是CATransformLayer,以允许子层的3D转换。
假设你有10个正方形的图像,代表卷轴上的符号。对于您的每个图像,创建一个CALayer,他的contents属性是您的图像之一。然后,对于每一层,你需要应用2个变换:
现在将这些层添加到视图的层中。现在,您应该看到一个围绕X轴的get“圆柱体”图像。
要旋转圆柱体,您需要调整第一个变换-要么使用CAAnimation,要么使用计时器并根据计时器触发的偏移量调整X轴旋转。
我将把它留给您来弄清楚完整的实现细节--但是这里有一些加载和创建初始"reel“的代码。
int imageCount = 16;
for (int i = 0; i < imageCount; i++) {
// Load image from the bundle
NSString * fileName = [NSString stringWithFormat: @"Image-%d", i];
NSString * filePath = [[NSBundle mainBundle] pathForResource: fileName ofType: @"jpeg"];
UIImage * image = [UIImage imageWithContentsOfFile: filePath];
// Create a layer with the image as content - My image size was 60x60
CALayer * imageLayer = [CALayer layer];
imageLayer.bounds = (CGRect){CGPointZero, {60.0, 60.0}};
imageLayer.contents = (id)image.CGImage;
imageLayer.position = (CGPoint){CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds)};
// Set the initial image transform - I've hardcoded the translate along the
// z-axis to 150, but this will vary depending on the number of images
// and their size - you'll need to do some maths to work it out... sines or
// cosines or somesuch
CGFloat angle = (2.0 * M_PI) / imageCount * i;
CATransform3D transform = CATransform3DMakeRotation(angle, 1.0, 0.0, 0.0);
transform = CATransform3DTranslate(transform, 0.0, 0.0, 150.0);
imageLayer.transform = transform;
[self.layers addObject: imageLayer];
[self.view.layer addSublayer: imageLayer];
}
}要旋转它,您只需更改变换的旋转部分。为了获得额外的积分,您可以在图层远离中心时添加越来越多的阴影。
发布于 2012-03-21 17:34:48
您可以为每个数字/符号使用UIImageView,并为您显示的图像的移动设置动画。使用UIPicker将限制为字母和数字;使用UIImageView,您可以添加其他典型的老虎机视觉效果,如樱桃等。
发布于 2012-03-21 17:46:59
我们在做你的作业吗?
并排使用垂直UIScrollViews,启用分页,视图使用UIImageViews。
默认情况下,它看起来是扁平的--但在功能上是等效的。
你需要一些核心动画/核心图形来使它看起来更像UIPickerView。
https://stackoverflow.com/questions/9801759
复制相似问题