1つのビューを2つのパートに分割し、上の部分を上にアニメーションし、下の部分を下にアニメーション化してその背後のビューを表示すると、トランジション効果を開発しようとしています。 は、私はそれを達成するためのUIViewとUIImageViewのアプローチを使用しています:UIViewを2つの部分にレンダリングする方法
// 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などを使用しています。 正しい方向に向けることができますか?
「極端に遅い」とはどういう意味ですか?インストゥルメントはどこに時間を費やしていると言いますか? –
正面図をクリックすると、トランジションが発生します。クリック後、目立つ遅延があり、アニメーションそのものがぎこちない(iPhone 4でテスト済み)。 – Lukasz