2014-09-24 125 views
0

我分類爲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 
        }]; 
} 

回答

0

我拿着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 

只要連接與此自定義動畫賽格瑞你的行動象下面這樣:因爲它只是一個不同的過渡動畫

enter image description here

+0

不能拿這個作爲一個答案。問題依然存在。它會導致相同的警告! – 2014-09-24 12:10:58

+0

它對我的工作很好。 – 2014-09-24 12:12:28