你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS自定義segue和自定義segue轉場動畫

iOS自定義segue和自定義segue轉場動畫

編輯:IOS開發綜合

自定義segue需要繼承 UIStoryboardSegue類,然後重寫-(void)perform;方法.在方法中可以自定義轉場動畫。


CoolSegue.h文件

#import 

@interface CoolSegue : UIStoryboardSegue

@end


CoolSegue.m文件

#import "CoolSegue.h"

@implementation CoolSegue



-(void)perform
{

    UIViewController* source = self.sourceViewController;

    UIViewController* destination = self.destinationViewController;

    UIGraphicsBeginImageContext(destination.view.bounds.size);
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    [destination.view.layer renderInContext:contextRef];
    UIImage* desImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIImageView* iView = [[UIImageView alloc] initWithImage:desImage];
    [iView setBackgroundColor:[UIColor grayColor]];
    iView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    iView.contentMode = UIViewContentModeCenter;

    [source.parentViewController.view addSubview:iView];

    CGAffineTransform scaleT = CGAffineTransformMakeScale(0.1, 0.1);

    CGAffineTransform rotateT = CGAffineTransformMakeRotation(M_PI);

    //iView.transform = CGAffineTransformConcat(scaleT, rotateT);
    iView.transform =CGAffineTransformTranslate(CGAffineTransformConcat(scaleT, rotateT), 1, 1);
    CGPoint originPoint =  iView.center;
    iView.center = CGPointMake(iView.bounds.size.width, iView.bounds.size.height);

    //iView.center = CGPointMake(originPoint.x -iView.bounds.size.width, originPoint.y);
    [UIView animateKeyframesWithDuration:0.8 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeCubic animations:^{
        iView.transform = CGAffineTransformIdentity;
        iView.center = originPoint;

    }completion:^(BOOL finished) {


        [self.sourceViewController presentViewController:self.destinationViewController animated:YES completion:nil];
         [iView removeFromSuperview];
    }];
}


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved