本文介绍了iPad版Twitter中的纸张折叠/展开效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

适用于iPad的Twitter实现了一种奇特的捏来扩大纸张折叠"效果.这里有一个简短的视频片段. http://www.youtube.com/watch?v=B0TuPsNJ-XY

Twitter for iPad implements a fancy "pinch to expand paper fold" effect. A short video clip here.http://www.youtube.com/watch?v=B0TuPsNJ-XY

可以在不使用OpenGL的情况下使用CATransform3D完成此操作吗?一个有效的例子将不胜感激.

Can this be done with CATransform3D without OpenGL? A working example would be thankful.

更新:我对这种动画效果的方法或实现感兴趣.这就是为什么我要悬赏这个问题-srikar

Update: I was interested in the approach or implementation to this animation effect. That's why I offered bounty on this question - srikar

推荐答案

这是一个使用手势识别器和CATransform3D入门的非常简单的示例.只需捏一下即可旋转灰色视图.

Here's a really simple example using a gesture recognizer and CATransform3D to get you started. Simply pinch to rotate the gray view.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...

    CGRect rect = self.window.bounds;
    view = [[UIView alloc] initWithFrame:CGRectMake(rect.size.width/4, rect.size.height/4,
                                                         rect.size.width/2, rect.size.height/2)];
    view.backgroundColor = [UIColor lightGrayColor];
    [self.window addSubview:view];

    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = -1/500.0; // this allows perspective
    self.window.layer.sublayerTransform = transform;

    UIPinchGestureRecognizer *rec = [[UIPinchGestureRecognizer alloc] initWithTarget:self
                                                                              action:@selector(pinch:)];
    [self.window addGestureRecognizer:rec];
    [rec release];

    return YES;
}

- (void)pinch:(UIPinchGestureRecognizer *)rec
{
    CATransform3D t = CATransform3DIdentity;
    t = CATransform3DTranslate(t, 0, -self.view.bounds.size.height/2, 0);
    t = CATransform3DRotate(t, rec.scale * M_PI, 1, 0, 0);
    t = CATransform3DTranslate(t, 0, -self.view.bounds.size.height/2, 0);
    self.view.layer.transform = t;
}

这篇关于iPad版Twitter中的纸张折叠/展开效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:24