iphone - 如何将 UIView 渲染成两部分

标签 iphone render transition quartz-graphics cgcontext

我正在尝试开发过渡效果,当一个 View 分成两部分时,上部动画向上,下部动画向下,以 Revel 其后面的 View 。 我正在使用 UIView 和 UIImageView 方法来实现这一点:

// 1. Make a screenshot:
    UIGraphicsBeginImageContext(parentView.frame.size);
    [parentView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // 2. Calculate rectangles for top and bottom part:
    CGRect rectTop, rectBottom;
    CGFloat W = rectBig.size.width;
    CGFloat H = rectBig.size.height;


    rectTop = CGRectMake(0, 0, W, y_cutoff);
    rectBottom = CGRectMake(0, y_cutoff, W, H - y_cutoff);

    // 3. Create top and bottom images:
    CGImageRef imageRefTop      = CGImageCreateWithImageInRect([screenshot CGImage], rectTop);
    CGImageRef imageRefBottom   = CGImageCreateWithImageInRect([screenshot CGImage], rectBottom);


    UIImage *imageTop = [UIImage imageWithCGImage:imageRefTop];
    UIImage *imageBottom = [UIImage imageWithCGImage:imageRefBottom];


// 4. Assign images to image views:
imageViewTop.image = imageTop;
imageViewBottom.image = imageBottom;

// 5. Animate image views:
[UIView beginAnimation:nil context:NULL];
.... animation code here
[UIView commitAnimations];

然而,这段代码在设备上速度非常慢,我确信有一种更有效的方法来实现这种转换。最有可能使用 CALayers 等。 你能指出我正确的方向吗?

最佳答案

这不是动画。你的绘图代码很慢。如果您进行分析,您会发现 renderInContext: (顺便说一句,始终在主线程上执行)和 CGImageCreateWithImageInRect 是限制因素。你的观点(你想要 split 的观点)是关于什么的?是否可以选择创建两个 View 而不是从一开始就创建一个 View ?

关于iphone - 如何将 UIView 渲染成两部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8436960/

相关文章:

iphone - iPhone 上的核心数据需要持久存储吗?

iOS5 : how to determine if the Notification Center for the app is turned ON/OFF

iphone - UIView底部不显示

当位置改变时,CSS 转换在 Firefox 中不起作用

iphone - "message sent to deallocated instance"- 无法找到保留方法。

ruby-on-rails - rails : render template looking for the wrong partial

jquery - 模板:XSLT 与 jQuery

javascript - 如何在 Ruby on Rails 4 中通过 CoffeeScript 进行渲染

qt - qml 中的边距变化动画

css - 过渡不是第一次发生