iOS 封装Modal动画代码

1.自定义转场动画要写的代码很多,如果整个项目的转场动画都必须一致,则必须考虑把modal代码封装起来

secondVC *second = [[secondVC alloc] init];

second.modalPresentationStyle = UIModalPresentationCustom;

second.transitioningDelegate = 自定义一个代理;

[self presentViewController:second animated:YES completion:nil];

2. 自定义代理对象

// MYTransition.h

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>

#import "Singleton.h"

@interface MYTransition : NSObject<UIViewControllerTransitioningDelegate>

SingletonH(MYTransition)

@end

// MYTransition.m

#import "MYTransition.h"

#import "MYPresentationController.h"

#import "MYAnimatedTransition.h"

#import "UIView+MJ.h"

@implementation MYTransition

SingletonM(MYTransition)

#pragma mark - UIViewControllerTransitioningDelegate

- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source

{

return [[MYPresentationController alloc]initWithPresentedViewController:presented presentingViewController:presenting];

}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source

{

MYAnimatedTransition *anima = [[MYAnimatedTransition alloc]init];

anima.show = YES;

return anima;

}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed

{

MYAnimatedTransition *anima = [[MYAnimatedTransition alloc]init];

anima.show = NO;

return anima;

}

@end

3. 使用封装好的Modal动画,就非常简单了

secondVC *second = [[secondVC alloc] init];

second.modalPresentationStyle = UIModalPresentationCustom;

second.transitioningDelegate = [MYTransition sharedMYTransition];

[self presentViewController:second animated:YES completion:nil];

时间: 2024-08-25 01:05:18

iOS 封装Modal动画代码的相关文章

ios中layer动画和UIView动画代码总结

kCATransitionFade淡出 kCATransitionMoveIn覆盖原图 kCATransitionPush推出 kCATransitionReveal底部显出来 pageCurl   向上翻一页 pageUnCurl 向下翻一页 rippleEffect 滴水效果 suckEffect 收缩效果,如一块布被抽走 cube 立方体效果 oglFlip 上下翻转效果 #pragma mark UIView 动画 - (IBAction)pressClick1:(id)sender {

IOS 制作动画代码和 设置控件透明度

方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 self.iconBtn.frame=CGRectMake(83,85,150,150); self.cover.alpha=0.0;//设置控件的透明度 } completion:^(BOOL finished) { //动画执行完毕后会自动调用这个block内部的代码 [self.cover re

[ios源码] 仿闲鱼二手交易平台-iOS源码-捡代码论坛

仿闲鱼二手交易平台-iOS源码-捡代码论坛 添加 首页模块和我的模块 首页水平滑动图利用自定义UICollectionViewFlowLayout实现 利用KVC,基于系统自带tabBar的进行定制实现底部TabBar. 页面跳转转场动画效果 封装刷新控件,仿闲鱼动画效果 动图演示(5.4M): Tag:闲鱼,iOS,动画,UICollectionView,视图布局 下载地址: 仿闲鱼二手交易平台-iOS源码-捡代码论坛http://bbs.jiandaima.com/thread-714-1-

iOS开发CABasicAnimation动画理解

1.CALayer简介 CALayer是个与UIView很类似的概念,同样有backgroundColor.frame等相似的属性,我们可以将UIView看做一种特殊的CALayer.但实际上UIView是对CALayer封装,在CALayer的基础上再添加交互功能.UIView的显示必须依赖于CALayer.我们同样可以跟新建view一样新建一个layer,然后添加到某个已有的layer上,同样可以对layer调整大小.位置.透明度等.一般来说,layer可以有两种用途:一是对view相关属性

iOS开发系列-动画绘图CALayer

代码下载地址:https://github.com/wwpeter/WW-MotionDemo.git 概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画.动画组.转场动画,如何通过UIView的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看到动画操作在iOS中是如何简单和高效,很多原来想做但是苦于没有思路的动画在iOS中将变得越发简单:

IOS三种动画方式

IOS开发UI篇—iOS开发中三种简单的动画设置 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView beginAnimations:nil context:nil]; //设置动画时长 [UIView setAnimationDuration:2.0]; self.headImageView.bounds = rect; // commitAnimations,将beginAnimation之后的所有动画提交并生成动画 [UIVie

iOS关于CoreAnimation动画知识总结

一:UIKit动画 在介绍CoreAnimation动画前先简单介绍一下UIKit动画,大部分简单的动画都可以使用UIKit动画实现,如果想实现更复杂的效果,则需要使用Core Animation了:UIKit动画有两种写法:它不仅可以针对视图还可以针对其它控件: 1:第一种写法是利用属性,结合beginAnimations.commitAnimations -(void)animationOfUIKit { UIView *redView=[[UIView alloc]initWithFram

iOS:自定义模态动画 --UIPresentationController

UIPresentationController :展示控制器,是iOS8的一个新特性,用来展示模态窗口的.它是所有模态控制器的管理者. 即: 1> 管理所有Modal出来的控制器 2> 管理所有通过- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion方法显示出来的控制器 3> 

自己定义modal动画

在非常多场景中.我们都须要实现各种动画.这回我们来尝试搞一下控制器间跳转的modal动画. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { ZYSecondViewController *second = [[ZYSecondViewController alloc]init]; second.modalTransitionStyle = UIModalTransitionStyleFl