在自定义stream行音乐播放期间,视图转换不会animation

当我将新的视图控制器推送到导航堆栈上时,我使用自定义的segue来创build展开animation。 如果prepareForSegue:sender:被调用时没有指定sourceRect,则目标视图控制器将从源视图控制器的中心展开。

ExpandSegue.m:

 - (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination { self = [super initWithIdentifier:identifier source:source destination:destination]; self.sourceRect = CGRectMake(source.view.center.x, source.view.center.y, 0.0, 0.0); return self; } - (void)perform { UIViewController *sourceViewController = (UIViewController *)self.sourceViewController; UIViewController *destinationViewController = (UIViewController *)self.destinationViewController; CGRect destinationRect = sourceViewController.view.frame; CGFloat tx = self.sourceRect.origin.x + self.sourceRect.size.width/2 - destinationRect.origin.x - destinationRect.size.width/2; CGFloat ty = self.sourceRect.origin.y + self.sourceRect.size.height/2 - destinationRect.origin.y - destinationRect.size.height/2; CGFloat sx = self.sourceRect.size.width/destinationRect.size.width; CGFloat sy = self.sourceRect.size.height/destinationRect.size.height; [sourceViewController.view addSubview:destinationViewController.view]; [destinationViewController.view setFrame:sourceViewController.view.frame]; [destinationViewController.view setTransform:CGAffineTransformConcat(CGAffineTransformMakeScale(sx, sy), CGAffineTransformMakeTranslation(tx, ty))]; [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^{ [destinationViewController.view setTransform:CGAffineTransformIdentity]; } completion:^(BOOL finished) { [destinationViewController.view removeFromSuperview]; [sourceViewController.navigationController pushViewController:destinationViewController animated:NO]; }]; } 

扩展赛格按预期工作。 我试图通过颠倒扩展segue的逻辑来创build一个collapse segue,但是这给了我一些问题。 我希望源视图控制器缩小到destinationRect的大小。 如果没有提供destinationRect,那么我希望视图缩小到目标视图控制器视图的中心。

CollapseSegue.m:

 - (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination { self = [super initWithIdentifier:identifier source:source destination:destination]; self.destinationRect = CGRectMake(source.view.center.x, source.view.center.y, 0.0, 0.0); return self; } - (void)perform { UIViewController *sourceViewController = (UIViewController *)self.sourceViewController; UIViewController *destinationViewController = (UIViewController *)self.destinationViewController; CGRect sourceRect = sourceViewController.view.frame; CGFloat tx = self.destinationRect.origin.x + self.destinationRect.size.width/2 - sourceRect.origin.x - sourceRect.size.width/2; CGFloat ty = self.destinationRect.origin.y + self.destinationRect.size.height/2 - sourceRect.origin.y - sourceRect.size.height/2; CGFloat sx = self.destinationRect.size.width/sourceRect.size.width; CGFloat sy = self.destinationRect.size.height/sourceRect.size.height; [sourceViewController.navigationController popViewControllerAnimated:NO]; [destinationViewController.view addSubview:sourceViewController.view]; [sourceViewController.view setFrame:destinationViewController.view.frame]; [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^{ [sourceViewController.view setTransform:CGAffineTransformConcat(CGAffineTransformMakeScale(sx, sy), CGAffineTransformMakeTranslation(tx, ty))]; } completion:^(BOOL finished) { [sourceViewController.view removeFromSuperview]; }]; } 

而不是很好的animation,sourceViewController的视图就好像我只调用了[sourceViewController.navigationController popViewControllerAnimated:NO]; 这似乎表明,我没有正确地设置我的视图层次,但我似乎无法弄清楚我要去哪里错了! 任何帮助将不胜感激。