用于iPad的Twitter中的纸张折叠/展开效果

Tim*_* Wu 33 animation core-animation objective-c ios

Twitter for iPad实现了一种奇特的"缩小纸张折叠"效果.这是一个简短的视频片段. http://www.youtube.com/watch?v=B0TuPsNJ-XY

CATransform3D没有OpenGL 可以做到这一点吗?一个工作的例子将是感恩的.

更新:我对此动画效果的方法或实现感兴趣.这就是我在这个问题上提供赏金的原因 - srikar

jtb*_*des 30

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

- (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;
}
Run Code Online (Sandbox Code Playgroud)

  • 这应该通过设置图层的anchorPoint属性来完成. (2认同)