Swift animation switches View level order

Source: Internet
Author: User

1. animation effect


2. Code

//// AppDelegate. swift // AnimationDemo /// Created by Zhao Chao on 14-6-27. // Copyright (c) 2014 Zhao Chao. all rights reserved. // import UIKit @ UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow? // Respond to the Click Event func onclick () {// start the animation UIView. beginAnimations ("test", context: nil) // animation duration UIView. setAnimationDuration (1) // FlipFromRight // CurlUp // animated style UIView. setAnimationTransition (UIViewAnimationTransition. curlUp, forView: self. window !, Cache: true) // change the view sequence self. window !. ExchangeSubviewAtIndex (0, withSubviewAtIndex: 1) // submit the animation UIView. commitAnimations ()} func application (application: UIApplication, didfinishlaunchingwitexceptions launchOptions: NSDictionary ?) -> Bool {self. window = UIWindow (frame: UIScreen. mainScreen (). bounds) // Override point for customization after application launch. self. window !. BackgroundColor = UIColor. whiteColor () self. window !. MakeKeyAndVisible () // The first view var vc1 = UIView (frame: UIScreen. mainScreen (). applicationFrame) vc1.backgroundColor = UIColor. grayColor () // The second view var vc2 = UIView (frame: UIScreen. mainScreen (). applicationFrame) vc2.backgroundColor = UIColor. blueColor () // Add and click the button var btn = UIButton (frame: CGRectMake (,) btn. backgroundColor = UIColor. redColor () btn. setTitle ("click to switch to View", forState :. normal) btn. addTarget (sel F, action: "onclick", forControlEvents: UIControlEvents. TouchUpInside) self. window !. AddSubview (btn) self. window !. AddSubview (vc1) self. window !. AddSubview (vc2) // place the button to the top self. window !. BringSubviewToFront (btn) return true} func applicationWillResignActive (application: UIApplication) {// Sent when the application is about to move from active to inactive state. this can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. games shocould use this method to pause the game .} func applicationDidEnterBackground (application: UIApplication) {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits .} func applicationWillEnterForeground (application: UIApplication) {// Called as part of the transition from the background to the inactive state; here you can undo changes of the changes made on entering the background .} func applicationDidBecomeActive (application: UIApplication) {// Restart any tasks that were paused (or not yet started) while the application was inactive. if the application was previusly in the background, optionally refresh the user interface .} func applicationWillTerminate (application: UIApplication) {// Called when the application is about to terminate. save data if appropriate. see also applicationDidEnterBackground :.}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.