I am trying to develop a transition effect when one view is divided into 2 parts, and the upper part is animated up and the lower part is animated down to look into it. I use UIView and UIImageView to achieve this:
// 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];
However, this code is very slow on the device, and I'm sure there is a more efficient way to implement such a transition. Most likely using CALayers, etc. Can you point me in the right direction?
source share