如何实现自定义segue动画?
问题描述:
我分类为UIStoryboardSegue
以执行自定义节奏动画。为了使动画可见,我必须添加目标为ViewController
的视图作为临时视图。执行动画后,我将删除临时视图并通过(presentViewController:animated:NO)呈现最终的ViewController
。如何实现自定义segue动画?
然而这会导致以下警告:“不平衡呼叫开始/结束外观转换为”。
如果我保留我的临时视图并且不删除它,警告不会出现,但最终视图不再响应触摸事件。如何摆脱这个警告?
我的自定义代码赛格瑞:
-(void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
destinationViewController.view.alpha = 0.;
destinationViewController.view.transform = CGAffineTransformScale(destinationViewController.view.transform, 4.0, 4.0);
[sourceViewController.view addSubview:destinationViewController.view];
[UIView animateWithDuration:kSSSpriteKitFadeOutDuration
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
destinationViewController.view.transform = CGAffineTransformScale(destinationViewController.view.transform, 0.25, 0.25);
destinationViewController.view.alpha = 1.;
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview]; // remove from temp super view
[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL]; // present VC
}];
}
答
我拿着4 UIStoryboardSegue
类型的类。 2为动画开始,2为动画停止。所以我打算分享4个班级的所有代码。请尝试解决这个问题。
CustomSegue.h
#import <UIKit/UIKit.h>
@interface CustomSegue : UIStoryboardSegue
// Originating point for animation
@property CGPoint originatingPoint;
@property CGRect Startingframe;
@end
CustomSegue.m
#import "CustomSegue.h"
@implementation CustomSegue
- (void)perform
{
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
// Add the destination view as a subview, temporarily
[sourceViewController.view addSubview:destinationViewController.view];
// Transformation start scale
float width = 320;
float height = 480;
float x_Scale = self.Startingframe.size.width/width;
float Y_Scale = self.Startingframe.size.height/height;
destinationViewController.view.transform = CGAffineTransformMakeScale(x_Scale, Y_Scale);
// Store original centre point of the destination view
CGPoint originalCenter = destinationViewController.view.center;
// Set center to start point of the button
destinationViewController.view.center = self.originatingPoint;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^
{
// Grow!
destinationViewController.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
destinationViewController.view.center = originalCenter;
}
completion:^(BOOL finished)
{
[destinationViewController.view removeFromSuperview]; // remove from temp super view
[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL]; // present VC
}];
}
@end
CustomUnwindSegue.h
CustomUnwindSegue.m
#import "CustomUnwindSegue.h"
@implementation CustomUnwindSegue
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
// Transformation End scale
float width = 320;
float height = 480;
float x_Scale = self.endFrame.size.width/width;
float Y_Scale = self.endFrame.size.height/height;
// Add view to super view temporarily
[sourceViewController.view.superview insertSubview:destinationViewController.view atIndex:0];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// Shrink!
sourceViewController.view.transform = CGAffineTransformMakeScale(x_Scale, Y_Scale);
sourceViewController.view.center = self.targetPoint;
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview]; // remove from temp super view
[sourceViewController dismissViewControllerAnimated:NO completion:NULL]; // dismiss VC
}];
}
@end
只要连接与此自定义动画赛格瑞你的行动象下面这样:因为它只是一个不同的过渡动画
不能拿这个作为一个答案。问题依然存在。它会导致相同的警告! – 2014-09-24 12:10:58
它对我的工作很好。 – 2014-09-24 12:12:28