首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIPicker的替代方案

UIPicker的替代方案
EN

Stack Overflow用户
提问于 2012-03-21 17:28:43
回答 3查看 935关注 0票数 1

老虎机应用程序还有其他方法吗?这是因为UIPICKER方法没有缓慢的动画效果。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-03-21 17:57:46

这可以使用CALayer动画来完成。

您的主slotMachineView层的类需要是CATransformLayer,以允许子层的3D转换。

假设你有10个正方形的图像,代表卷轴上的符号。对于您的每个图像,创建一个CALayer,他的contents属性是您的图像之一。然后,对于每一层,你需要应用2个变换:

  • 首先你需要绕X轴旋转每一层(2 * PI) / 10
  • ,然后沿着Z轴平移一段距离(需要计算)。

现在将这些层添加到视图的层中。现在,您应该看到一个围绕X轴的get“圆柱体”图像。

要旋转圆柱体,您需要调整第一个变换-要么使用CAAnimation,要么使用计时器并根据计时器触发的偏移量调整X轴旋转。

我将把它留给您来弄清楚完整的实现细节--但是这里有一些加载和创建初始"reel“的代码。

代码语言:javascript
复制
    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];
    }
}

要旋转它,您只需更改变换的旋转部分。为了获得额外的积分,您可以在图层远离中心时添加越来越多的阴影。

票数 3
EN

Stack Overflow用户

发布于 2012-03-21 17:34:48

您可以为每个数字/符号使用UIImageView,并为您显示的图像的移动设置动画。使用UIPicker将限制为字母和数字;使用UIImageView,您可以添加其他典型的老虎机视觉效果,如樱桃等。

票数 2
EN

Stack Overflow用户

发布于 2012-03-21 17:46:59

我们在做你的作业吗?

并排使用垂直UIScrollViews,启用分页,视图使用UIImageViews。

默认情况下,它看起来是扁平的--但在功能上是等效的。

你需要一些核心动画/核心图形来使它看起来更像UIPickerView。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9801759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档