使用CoreAnimation或OpenGL弯曲/扭曲视图以获得轮播效果 [英] Curving/warping views with CoreAnimation or OpenGL for carousel effect

查看:481
本文介绍了使用CoreAnimation或OpenGL弯曲/扭曲视图以获得轮播效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用一系列视图填充UIScrollView。需要对视图进行扭曲以使UIScrollView看起来像旋转木马。换句话说,当用户滚动时,它需要像一个圆圈。我之前从未做过这样的事情,但我认为CoreAnimation是不可能的,需要使用OpenGL。如果使用CoreAnimation或Quartz可以实现这一点,那么我真的只需要一个关于如何扭曲视图的示例,我可以自己解决剩下的问题,但我不熟悉OpenGL。

Right now I'm populating a UIScrollView with a series of views. The views need to be warped to make the UIScrollView appear like a carousel. In other words when the user scrolls it needs to be like a circle. I've never done anything quite like this before, but I'm assuming CoreAnimation is out of the question and OpenGL needs to be used. If this is possible with CoreAnimation or Quartz then I really just need a sample on how to warp the views and I can figure the rest out myself but I'm not familiar with OpenGL.

推荐答案

根据我的经验,让价值观正确有点棘手。提供视图透视的方法是通过操纵它的图层变换。我已经使用以下方法来实现类似效果的转换:

In my experience, it is a bit tricky to get the values right. The way to give a view perspective is by manipulating it's layer transform. I have used the following method to achieve the transfor for a similar effect:

-(CATransform3D)makeTransformForAngle:(CGFloat)angle from:(CATransform3D)start{

    CATransform3D transform = start;


    // the following two lines are the key to achieve the perspective effect
CATransform3D persp = CATransform3DIdentity;
    persp.m34 = 1.0 / -1000;

    transform = CATransform3DConcat(transform, persp);
        transform = CATransform3DRotate(transform,angle, 0.0, 1.0, 0.0);
    return transform;
}

这样做是为了创建一个翻页动画,所以你可能需要去适应。要使用它,请执行以下操作:

This was done to create a "flip page" animation, so you may need to adapt. To use it, do the following:

flip_page.layer.transform = [self makeTransformForAngle:angle from:CATransform3DIdentity];

其中flip_page是UIView。干杯!

where flip_page is a UIView. Cheers!

这篇关于使用CoreAnimation或OpenGL弯曲/扭曲视图以获得轮播效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆