我有两个视图"A"和"B"。A浮动在窗口中间(不是全屏)。B是全屏的,将替换A。我想编写一个自定义转换,将A翻转以显示B的背面,但同时缩放翻转矩形,以便翻转完成后,B变成全屏。
我尝试使用transitionFromView:toView:duration:options:completion提供的翻转过渡效果,但我只能让它翻转整个屏幕,而不是从A的框架开始并以B的框架结束。
我知道可以对视图的图层进行类似3D的变换,但我不确定应该使用哪一组动画API来实现这一点。我尝试的一件事是在transitionWithView:duration:options:animations:completion的动画块中修改视图的图层属性,但这并没有起作用,因为它似乎只尊重视图属性修改。
有人可以指点我正确的方向吗?非常感谢。
更新:这里是我的代码,用于实现此效果。您可以在此处查看其操作视频:http://www.youtube.com/watch?v=-xNMD2fGRwg
我尝试使用transitionFromView:toView:duration:options:completion提供的翻转过渡效果,但我只能让它翻转整个屏幕,而不是从A的框架开始并以B的框架结束。
我知道可以对视图的图层进行类似3D的变换,但我不确定应该使用哪一组动画API来实现这一点。我尝试的一件事是在transitionWithView:duration:options:animations:completion的动画块中修改视图的图层属性,但这并没有起作用,因为它似乎只尊重视图属性修改。
有人可以指点我正确的方向吗?非常感谢。
更新:这里是我的代码,用于实现此效果。您可以在此处查看其操作视频:http://www.youtube.com/watch?v=-xNMD2fGRwg
CGRect frame = [[UIApplication easybookDelegate] rootViewController].view.bounds ;
float statusHeight = [UIApplication sharedApplication].statusBarFrame.size.height ;
frame.origin.y = statusHeight ;
frame.size.height -= statusHeight ;
self.view.frame = frame ; // self.view is view "B"
// Put the snapshot as thet topmost view of our view
UIImageView *imageView = [[UIImageView alloc] initWithImage:image] ; // image is a snapshot of view "A"
imageView.frame = self.view.bounds ;
[self.view addSubview:imageView] ;
[self.view bringSubviewToFront:imageView] ;
// Pre-transform our view (s=target/current, d=target-current)
CGAffineTransform transform = CGAffineTransformIdentity ;
// Translate our view
CGPoint center = CGPointMake(screenOrigin.x + (image.size.width/2.0), screenOrigin.y + (image.size.height/2.0)) ;
float dX = center.x - self.view.center.x ;
float dY = center.y - self.view.center.y ;
NSLog( @"dx: %f, dy: %f" , dX, dY ) ;
transform = CGAffineTransformTranslate(transform, dX, dY) ;
// Scale our view
float scaleWFactor = image.size.width / self.view.frame.size.width ;
float scaleHFactor = image.size.height / self.view.frame.size.height ;
transform = CGAffineTransformScale(transform,scaleWFactor, scaleHFactor) ;
self.view.transform = transform ;
[[[UIApplication easybookDelegate] rootViewController].view addSubview:self.view] ;
// Perform the animation later since implicit animations don't seem to work due to
// view "B" just being added above and hasn't had a chance to become visible. Right now
// this is just on a timer for debugging purposes. It'll probably be moved elsewhere, probably
// to view "B"'s -didMoveToSuperview
double delayInSeconds = 0.3;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[UIView transitionWithView:self.view duration:3 options:UIViewAnimationOptionTransitionFlipFromRight| UIViewAnimationOptionCurveEaseOut animations:^(void)
{
[imageView removeFromSuperview] ;
self.view.transform = CGAffineTransformIdentity ;
}
completion:^(BOOL finished){
[self.view removeFromSuperview] ;
[navController presentModalViewController:self animated:NO] ;
}] ;
});
[imageView release];