为UIView视图切换添加动画效果

我们定义了一个动画类来实现视图切换的动画效果,这个类只包含一个类方法,可直接调用,具体代码如下:

头文件:

+ ?





1

2

3

4

5

6

7

8

9

10

11

12

13

#import <Foundation/Foundation.h>

@interface
ViewAnimation : NSObject

/*============================页面切换的方法==============================

    View1 表示当前页面

    View2 表示目标页面

    VC    两个view所在的viewController

    共有12种动画效果和四个动画方向,这里采用随机挑选动画和方向的方案

======================================================================*/

+(void)TransView1:(UIView*)v1 View2:(UIView*)v2 VC:(UIViewController*)vc;

@end

体文件:

+ ?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

#import "ViewAnimation.h"

#import <QuartzCore/QuartzCore.h>

#define kDuration 0.4       //  动画效果持续时间(秒)

@implementation
ViewAnimation

//  页面切换的方法

+(void)TransView1:(UIView*)v1 View2:(UIView*)v2 VC:(UIViewController *)vc;

{

    CATransition *animation = [CATransition animation];

    animation.delegate = self;

    animation.duration = kDuration;

    animation.timingFunction = UIViewAnimationCurveEaseInOut;

    

    switch
(rand()%11) {

        case
1:

            animation.type = kCATransitionFade;

            break;

        case
2:

            animation.type = kCATransitionPush;

            break;

        case
3:

            animation.type = kCATransitionReveal;

            break;

        case
4:

            animation.type = kCATransitionMoveIn;

            break;

        case
5:

            animation.type = @"cube";

            break;

        case
6:

            animation.type = @"suckEffect";

            break;

        case
7:

            animation.type = @"oglFlip";

            break;

        case
8:

            animation.type = @"rippleEffect";

            break;

        case
9:

            animation.type = @"pageCurl";

            break;

        case
10:

            animation.type = @"pageUnCurl";

            break;

        case
11:

            animation.type = @"cameraIrisHollowOpen";

            break;

        case
0:

            animation.type = @"cameraIrisHollowClose";

            break;

        default:

            animation.type = kCATransitionMoveIn;

            break;

    }

    

    switch
(rand()%3) {

        case
0:

            animation.subtype = kCATransitionFromLeft;

            break;

        case
1:

            animation.subtype = kCATransitionFromBottom;

            break;

        case
2:

            animation.subtype = kCATransitionFromRight;

            break;

        case
3:

            animation.subtype = kCATransitionFromTop;

            break;

        default:

            animation.subtype = kCATransitionFromRight;

            break;

    }

    

    [vc.view addSubview:v2];

    

    NSInteger
x1 = [[vc.view subviews]indexOfObject:v1];

    NSInteger
x2 = [[vc.view subviews]indexOfObject:v2];

    

    [vc.view exchangeSubviewAtIndex:x1 withSubviewAtIndex:x2];

    [[vc.view layer]addAnimation:animation forKey:@"animation"];

}

@end

为UIView视图切换添加动画效果,码迷,mamicode.com

时间: 2024-10-06 01:20:47

为UIView视图切换添加动画效果的相关文章

viewpager切换添加动画效果viewpager切换添加动画效果--IT蓝豹

viewpager切换添加动画效果,本项目中主要有三种切换特效,(1):DepthPageTransformer 效果(2):RotateDownPageTransformer 每一个view切换的时候旋转(3):ZoomOutPageTransformer 效果主要实现代码:  mViewPager.setPageTransformer(true,new ZoomOutPageTransformer());  mViewPager.setPageTransformer(true,new Rot

实现多个UIView之间切换的动画效果

@interface RootViewController (){ UIView *view1; UIView *view2; int flag; } @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; flag = 1; UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(130, 65, 50, 35)]; [

ios 视图切换翻页效果

本文写的是视图切换,涉及到的内容有 1.实现代码添加Navigation Bar  Toolbal: 2.实现在Navigation Bar和Toolbar上用代码添加Bar Button Item: 3.UIView层面的简单动画效果 先把实现结果功能截图贴出来,对应动画效果 开始界面 和第一次向上翻页 向上翻页 和向下翻页 从左向右翻页 和从右向左翻页 开始制作: 1.创建一个新工程叫NVDemo: File->New->Project ->single View Applicati

布局添加动画效果

1. 布局添加动画效果 ① 视图 五个按钮 <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent&q

AndroidScreenSlide项目切换view动画效果

AndroidScreenSlide项目切换view动画效果 AndroidScreenSlide项目中有几个不错的效果,一:Card Flip翻页立体效果,二:Screen Slide 左右切换view时候和新加载view呈现效果,三:Layout Changes添加每一个item效果和删除每一个item效果.四:Advanced Screen Slide切换viewpager时页面切换动画效果.本项目来源:https://github.com/xiongwei-git/AndroidScre

页面跳转添加动画效果

CATransition *animation = [CATransition animation];//初始化 [animation setDuration:0.5];//设置时间间隔 [animation setType: kCATransitionReveal]; [animation setSubtype: kCATransitionFromTop]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName

AndroidScreenSlide项目切换view动画效果《IT蓝豹》

AndroidScreenSlide项目切换view动画效果 AndroidScreenSlide项目中有几个不错的效果,一:Card Flip翻页立体效果,二:Screen Slide 左右切换view时候和新加载view呈现效果,三:Layout Changes添加每一个item效果和删除每一个item效果.四:Advanced Screen Slide切换viewpager时页面切换动画效果.本项目来源:https://github.com/xiongwei-git/AndroidScre

Android Activity界面切换添加动画特效

在Android 2.0之后有了overridePendingTransition() ,其中里面两个参数,一个是前一个activity的退出两一个activity的进入, Java代码   @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.SplashScreen); new Handler().postD

IOS视图缩放显示动画效果

效果:视图从大--小缩放显示/小--大 (只是比例问题) 方法1.直接show出view的时候:把下面的这段代码加到viewController或者view出现的时候就OK self.view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);//将要显示的view按照正常比例显示出来  [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];  [UIView se