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

相关文章

Spring Bean初始化及@PostConstruc执行顺序示例详解

《SpringBean初始化及@PostConstruc执行顺序示例详解》本文给大家介绍SpringBean初始化及@PostConstruc执行顺序,本文通过实例代码给大家介绍的非常详细,对大家的... 目录1. Bean初始化执行顺序2. 成员变量初始化顺序2.1 普通Java类(非Spring环境)(

浅析Spring如何控制Bean的加载顺序

《浅析Spring如何控制Bean的加载顺序》在大多数情况下,我们不需要手动控制Bean的加载顺序,因为Spring的IoC容器足够智能,但在某些特殊场景下,这种隐式的依赖关系可能不存在,下面我们就来... 目录核心原则:依赖驱动加载手动控制 Bean 加载顺序的方法方法 1:使用@DependsOn(最直

IDEA中新建/切换Git分支的实现步骤

《IDEA中新建/切换Git分支的实现步骤》本文主要介绍了IDEA中新建/切换Git分支的实现步骤,通过菜单创建新分支并选择是否切换,创建后在Git详情或右键Checkout中切换分支,感兴趣的可以了... 前提:项目已被Git托管1、点击上方栏Git->NewBrancjsh...2、输入新的分支的

Spring如何使用注解@DependsOn控制Bean加载顺序

《Spring如何使用注解@DependsOn控制Bean加载顺序》:本文主要介绍Spring如何使用注解@DependsOn控制Bean加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录1.javascript 前言2. 代码实现总结1. 前言默认情况下,Spring加载Bean的顺

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的执行顺序