아주 독특한 애니메이션을 만들고 싶습니다. 지난 달에 나는 그와 비슷한 것을 가지고 놀았습니다. 내 솔루션은 현재보기에 오버레이로 사용자 지정보기 (보기 컨트롤러에서 가져온 것일 수도 있음)를 추가하는 것이 었습니다. 레이어와도 작동합니다.
먼저 위의 코드 예제에서와 같이 "미래"또는 "현재"보기 컨트롤러에서 이미지를 가져옵니다. 일반적으로 컨텍스트에 렌더링하는 동안 뷰 컨트롤러 컨텐트를 사용할 수 있어야합니다.
이제 이미지가 생겼습니다. 이미지 조작은 당신이해야합니다.
이미지를 UIImageView에 추가하십시오. 이 ImageView는 하위 뷰 또는 레이어로 추가 될 수 있습니다. 이제 실제 사용자 인터페이스 위에 자유롭게 그릴 수있는 레이어가 있습니다. 때로는 레이어 또는보기를 이동해야하므로보기가 완벽하게 오버레이됩니다. 이는보기 설정에 따라 다릅니다. Tableviews를 다루는 경우, 하위 뷰를 추가하는 것은 쉽지 않습니다. 따라서 레이어를 더 잘 사용하십시오.
모든 작업이 끝나면 즉시 애니메이션이 표시되지 않도록 새보기 컨트롤러를 표시합니다.
작업이 완료된 후 부모보기에서 레이어 또는보기를 제거하고 정리하십시오.
이 작업은 복잡해 보이지만 일단 작업을 완료하면 템플릿을 사용할 수 있습니다. "WWDC 2011, Session 309 Interface Builder Storyboarding 소개"에서 Apple은 '원하는 맞춤 구문'을 소개했습니다. 여기서는 원하는 작업을 정확하게 찾을 수 있습니다. 아래의 코드는 이전 프로젝트에서 삭제 된 것으로 여하튼 엉망이며 정리해야합니다. 그러나 원리를 보여주기 위해 이것은 작동해야합니다 :
-(void) animate {
static LargeViewController* lvc = [[LargeViewController alloc] init];
UIGraphicsBeginImageContextWithOptions(self.bounds.size, view.opaque, [[UIScreen mainScreen] scale]);
[lvc.view.layer renderInContext:UIGraphicsGetCurrentContext()];
// Create a ImageView to display your "zoomed" image
static UIImageView* displayView = [[UIImageView alloc] initWithFrame:self.view.frame];
static UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Add your image to the view
displayView.image = img;
// insert the view above your actual view, adjust coordinates in the
// frame property of displayView if overlay is misaligned
[[self.view] addSubview:displayView];
// alternatively you can use the layer
// [self.view.layer addSublayer:displayView.layer];
// draw the imageView
[displayView setNeedsDisplay];
// do something in background. You may create your own
// construction, i.e. using a timer
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSDate *now = [NSDate date];
NSTimeInterval animationDuration = 3.;
NSTimeInterval t = -[now timeIntervalSinceNow];
while (t < animationDuration) {
t = -[now timeIntervalSinceNow];
// Do some animation here, by manipulation the image
// or the displayView
// <calculate animation>, do something with img
// you have exact timing information in t,
// so you can set the scalefactor derived from t
// You must not use an UIImage view. You can create your own view
// and do sth. in draw rect. Do whatever you want,
// the results will appear
// in the view if you added a subview
// or in a layer if you are using the layer
dispatch_sync(dispatch_get_main_queue(), ^{
// display the result
displayView.image = img;
[displayView setNeedsDisplay];
});
}
});
// now the animation is done, present the real view controller
[self presentModalViewController:lvc animated:NO];
// and clean up here
}
마침내 당신의 매우 상세한 제안을 시험 할 시간이있었습니다. 매력처럼 작동합니다! 귀하의 의견을 보내 주셔서 감사합니다. 또한 WWDC 2011 세션 309는 커스텀 스팽글을 사용하여 효과적이었을 것입니다. –