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

相关文章

Java中JSON格式反序列化为Map且保证存取顺序一致的问题

《Java中JSON格式反序列化为Map且保证存取顺序一致的问题》:本文主要介绍Java中JSON格式反序列化为Map且保证存取顺序一致的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未... 目录背景问题解决方法总结背景做项目涉及两个微服务之间传数据时,需要提供方将Map类型的数据序列化为co

SpringBoot实现多环境配置文件切换

《SpringBoot实现多环境配置文件切换》这篇文章主要为大家详细介绍了如何使用SpringBoot实现多环境配置文件切换功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 示例代码结构2. pom文件3. application文件4. application-dev文

Kotlin Compose Button 实现长按监听并实现动画效果(完整代码)

《KotlinComposeButton实现长按监听并实现动画效果(完整代码)》想要实现长按按钮开始录音,松开发送的功能,因此为了实现这些功能就需要自己写一个Button来解决问题,下面小编给大... 目录Button 实现原理1. Surface 的作用(关键)2. InteractionSource3.

使用WPF实现窗口抖动动画效果

《使用WPF实现窗口抖动动画效果》在用户界面设计中,适当的动画反馈可以提升用户体验,尤其是在错误提示、操作失败等场景下,窗口抖动作为一种常见且直观的视觉反馈方式,常用于提醒用户注意当前状态,本文将详细... 目录前言实现思路概述核心代码实现1、 获取目标窗口2、初始化基础位置值3、创建抖动动画4、动画完成后

使用animation.css库快速实现CSS3旋转动画效果

《使用animation.css库快速实现CSS3旋转动画效果》随着Web技术的不断发展,动画效果已经成为了网页设计中不可或缺的一部分,本文将深入探讨animation.css的工作原理,如何使用以及... 目录1. css3动画技术简介2. animation.css库介绍2.1 animation.cs

MySQL中SQL的执行顺序详解

《MySQL中SQL的执行顺序详解》:本文主要介绍MySQL中SQL的执行顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql中SQL的执行顺序SQL执行顺序MySQL的执行顺序SELECT语句定义SELECT语句执行顺序总结MySQL中SQL的执行顺序

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

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.