设为首页 加入收藏

TOP

transitionFromView方法的使用
2017-10-13 10:28:29 】 浏览:723
Tags:transitionFromView 方法 使用

transitionFromView方法的使用

 

效果

 

源码

//
//  ViewController.m
//  TransitionFromView
//
//  Created by YouXianMing on 16/5/30.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "ViewController.h"

typedef enum : NSUInteger {
    
    kBottomView = 1000,
    kTopView,
    
} EViewControllerTag;

@interface ViewController () {

    UIView *redView;
    UIView *yellowView;
    UIView *containerView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    // ContainerView
    containerView         = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 350)];
    containerView.center  = self.view.center;
    [self.view addSubview:containerView];
    
    // BottomView
    redView                 = [[UIView alloc] initWithFrame:containerView.bounds];
    redView.tag             = kBottomView;
    redView.backgroundColor = [UIColor redColor];
    [containerView addSubview:redView];
    
    // TopView
    yellowView                 = [[UIView alloc] initWithFrame:containerView.bounds];
    yellowView.tag             = kTopView;
    yellowView.backgroundColor = [UIColor yellowColor];
    [containerView addSubview:yellowView];
    
    // Button
    UIButton *button = [[UIButton alloc] initWithFrame:self.view.bounds];
    [button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)buttonEvent:(UIButton *)button {
    
    button.enabled = NO;
    
    [UIView transitionFromView:[containerView viewWithTag:kTopView]
                        toView:[containerView viewWithTag:kBottomView]
                      duration:0.5f
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    completion:^(BOOL finished) {
                        
                        button.enabled = YES;
                        
                        if ([[containerView viewWithTag:kBottomView] isEqual:redView]) {
                            
                            [containerView insertSubview:yellowView belowSubview:redView];
                            redView.tag    = kTopView;
                            yellowView.tag = kBottomView;
                            
                        } else {
                        
                            [containerView insertSubview:redView belowSubview:yellowView];
                            redView.tag    = kBottomView;
                            yellowView.tag = kTopView;
                        }
                    }];
}

@end

 

细节

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【IOS】模仿windowsphone列表索引.. 下一篇iOS原生CIFilter创建二维码

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目