Use of the transitionFromView method, transitionfromview
Use of the transitionFromView Method
Effect
Source code
/// 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 finished: [containerView viewWithTag: kTopView] toView: [containerView viewWithTag: kBottomView] duration: 0.5f options: Completed 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
Details