swift 动画切换View心地层次顺序

2024-05-31 06:32

本文主要是介绍swift 动画切换View心地层次顺序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.动画效果




2.代码

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //  
  2. //  AppDelegate.swift  
  3. //  AnimationDemo  
  4. //  
  5. //  Created by 赵超 on 14-6-27.  
  6. //  Copyright (c) 2014年 赵超. All rights reserved.  
  7. //  
  8.   
  9. import UIKit  
  10.   
  11. @UIApplicationMain  
  12. class AppDelegate: UIResponder, UIApplicationDelegate {  
  13.                               
  14.     var window: UIWindow?  
  15.     //响应点击事件  
  16.     func onclick(){  
  17.         //开始动画  
  18.         UIView.beginAnimations("test",context: nil)  
  19.         //动画时长  
  20.         UIView.setAnimationDuration(1)  
  21.         // FlipFromRight  
  22.         // CurlUp  
  23.         //动画样式  
  24.         UIView.setAnimationTransition(UIViewAnimationTransition.CurlUp,  
  25.             forView :self.window!,  
  26.             cache:true)  
  27.         //更改view顺序  
  28.         self.window!.exchangeSubviewAtIndex(0,withSubviewAtIndex :1)  
  29.         //提交动画  
  30.         UIView.commitAnimations()  
  31.   
  32.     }  
  33.     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {  
  34.         self.window = UIWindow(frame: UIScreen.mainScreen().bounds)  
  35.         // Override point for customization after application launch.  
  36.         self.window!.backgroundColor = UIColor.whiteColor()  
  37.         self.window!.makeKeyAndVisible()  
  38.           
  39.         //第一个view  
  40.         var vc1=UIView(frame:UIScreen.mainScreen().applicationFrame)  
  41.         vc1.backgroundColor=UIColor.grayColor()  
  42.         //第二个view  
  43.         var vc2 = UIView(frame:UIScreen.mainScreen().applicationFrame)  
  44.         vc2.backgroundColor=UIColor.blueColor()  
  45.         //添加点击按钮  
  46.         var btn=UIButton(frame:CGRectMake(40,40,200,40))  
  47.         btn.backgroundColor=UIColor.redColor()  
  48.         btn.setTitle("点击切换View",forState: .Normal)  
  49.         btn.addTarget(self,action:"onclick",forControlEvents : UIControlEvents.TouchUpInside)  
  50.           
  51.         self.window!.addSubview(btn)  
  52.         self.window!.addSubview(vc1)  
  53.         self.window!.addSubview(vc2)  
  54.         //将按钮放到顶层  
  55.         self.window!.bringSubviewToFront(btn)  
  56.           
  57.           
  58.         return true  
  59.     }  
  60.   
  61.     func applicationWillResignActive(application: UIApplication) {  
  62.         // 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.  
  63.         // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.  
  64.     }  
  65.   
  66.     func applicationDidEnterBackground(application: UIApplication) {  
  67.         // 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.  
  68.         // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.  
  69.     }  
  70.   
  71.     func applicationWillEnterForeground(application: UIApplication) {  
  72.         // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.  
  73.     }  
  74.   
  75.     func applicationDidBecomeActive(application: UIApplication) {  
  76.         // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.  
  77.     }  
  78.   
  79.     func applicationWillTerminate(application: UIApplication) {  
  80.         // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.  
  81.     }  
  82.   
  83.   
  84. }  

这篇关于swift 动画切换View心地层次顺序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1017511

相关文章

Pytest多环境切换的常见方法介绍

《Pytest多环境切换的常见方法介绍》Pytest作为自动化测试的主力框架,如何实现本地、测试、预发、生产环境的灵活切换,本文总结了通过pytest框架实现自由环境切换的几种方法,大家可以根据需要进... 目录1.pytest-base-url2.hooks函数3.yml和fixture结论你是否也遇到过

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

JDK多版本共存并自由切换的操作指南(本文为JDK8和JDK17)

《JDK多版本共存并自由切换的操作指南(本文为JDK8和JDK17)》本文介绍了如何在Windows系统上配置多版本JDK(以JDK8和JDK17为例),并通过图文结合的方式给大家讲解了详细步骤,具有... 目录第一步 下载安装JDK第二步 配置环境变量第三步 切换JDK版本并验证可能遇到的问题前提:公司常

nvm如何切换与管理node版本

《nvm如何切换与管理node版本》:本文主要介绍nvm如何切换与管理node版本问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录nvm切换与管理node版本nvm安装nvm常用命令总结nvm切换与管理node版本nvm适用于多项目同时开发,然后项目适配no

Python中顺序结构和循环结构示例代码

《Python中顺序结构和循环结构示例代码》:本文主要介绍Python中的条件语句和循环语句,条件语句用于根据条件执行不同的代码块,循环语句用于重复执行一段代码,文章还详细说明了range函数的使... 目录一、条件语句(1)条件语句的定义(2)条件语句的语法(a)单分支 if(b)双分支 if-else(

关于Spring @Bean 相同加载顺序不同结果不同的问题记录

《关于Spring@Bean相同加载顺序不同结果不同的问题记录》本文主要探讨了在Spring5.1.3.RELEASE版本下,当有两个全注解类定义相同类型的Bean时,由于加载顺序不同,最终生成的... 目录问题说明测试输出1测试输出2@Bean注解的BeanDefiChina编程nition加入时机总结问题说明

C++实现封装的顺序表的操作与实践

《C++实现封装的顺序表的操作与实践》在程序设计中,顺序表是一种常见的线性数据结构,通常用于存储具有固定顺序的元素,与链表不同,顺序表中的元素是连续存储的,因此访问速度较快,但插入和删除操作的效率可能... 目录一、顺序表的基本概念二、顺序表类的设计1. 顺序表类的成员变量2. 构造函数和析构函数三、顺序表

Oracle数据库如何切换登录用户(system和sys)

《Oracle数据库如何切换登录用户(system和sys)》文章介绍了如何使用SQL*Plus工具登录Oracle数据库的system用户,包括打开登录入口、输入用户名和口令、以及切换到sys用户的... 目录打开登录入口登录system用户总结打开登录入口win+R打开运行对话框,输php入:sqlp

IDEA如何切换数据库版本mysql5或mysql8

《IDEA如何切换数据库版本mysql5或mysql8》本文介绍了如何将IntelliJIDEA从MySQL5切换到MySQL8的详细步骤,包括下载MySQL8、安装、配置、停止旧服务、启动新服务以及... 目录问题描述解决方案第一步第二步第三步第四步第五步总结问题描述最近想开发一个新应用,想使用mysq