Objective C - 自定义segue调用两次

时间:2014-04-21 13:18:19

标签: ios objective-c segue

我正在使用网上提供的自定义segue代码。

但每次我使用它时,目标控制器的viewDidLoad都会被调用两次!

我使用此代码,因为它像假冒"推"回来&前进动画(我不想使用原作" push" segue)。

此代码有什么问题?

以下是我的代码: .h文件

#import <UIKit/UIKit.h>

@interface MyCustomSeguePushForward : UIStoryboardSegue

@end

.m文件

#import "MyCustomSeguePushForward.h"

@implementation MyCustomSeguePushForward

-(void) perform
{
UIView *preV = ((UIViewController *)self.sourceViewController).view;
UIView *newV = ((UIViewController *)self.destinationViewController).view;

UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
newV.center = CGPointMake(preV.center.x + preV.frame.size.width, newV.center.y);
[window insertSubview:newV aboveSubview:preV];

[UIView animateWithDuration:0.4
                 animations:^{
                     newV.center = CGPointMake(preV.center.x, newV.center.y);
                     preV.center = CGPointMake(0- preV.center.x, newV.center.y);}
                 completion:^(BOOL finished){
                     [preV removeFromSuperview];
                     window.rootViewController = self.destinationViewController;
                 }];
}



@end

实施

ProfilePicturesCollectionView *Pictures = [self.storyboard instantiateViewControllerWithIdentifier:@"Picture"];
MyCustomSeguePushForward *segue = [[MyCustomSeguePushForward alloc] initWithIdentifier:@"CustomSeguePushForward" source:self destination:Pictures];
[segue perform];

0 个答案:

没有答案