zoukankan      html  css  js  c++  java
  • iOS Swift最简单的Animation

    最近发现Animation是一个iOS开发中非常好玩的元素,能给应用的交互性增色不少。比如很多音乐应用的菜单从底部弹出和隐藏的效果。

    Animation最核心的当然就是UIView的animateWithDuration这个类方法了,另外有个博客介绍了很多animation的文章也很不错:

    http://www.devtalking.com/articles/uiview-animation-practice/

    念在好久没用swift开发了,于是花了几分钟写了个简单的demo复习下

    //
    //  ViewController.swift
    //  UIAnimationTest
    //
    //  Created by shen on 15/10/24.
    //  Copyright © 2015年 shen. All rights reserved.
    //
    
    import UIKit
    
    class ViewController: UIViewController {
    
        var popView:UIView!
        var clkbtn:UIButton!=UIButton()
        var display:Bool=false
        
        override func viewDidLoad() {
            super.viewDidLoad()
            popView=UIView();
            popView.frame=CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width, 100);
            popView.backgroundColor=UIColor.redColor();
            self.view.addSubview(popView);
            
            clkbtn=UIButton();
            clkbtn.frame=CGRectMake(self.view.frame.size.width/2-30, self.view.frame.size.height/2-20, 60, 40);
            clkbtn.setTitle("弹出", forState: UIControlState.Normal);
            clkbtn.backgroundColor=UIColor.grayColor();
            clkbtn.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside);
            self.view.addSubview(clkbtn);
            
                }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
        func buttonClicked(sender:UIButton)
        {
            if(display==false){
                display=true;
                clkbtn.setTitle("隐藏", forState: UIControlState.Normal);
                UIView.animateWithDuration(0.5, animations: {
                    self.popView.frame=CGRectMake(0,self.view.frame.size.height-100, self.view.frame.size.width, 100);
                    }, completion: nil);
            }else{
                display=false;
                clkbtn.setTitle("弹出", forState: UIControlState.Normal);
                UIView.animateWithDuration(0.5, animations: {
                    self.popView.frame=CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width, 100);
                    }, completion: nil);
            }
        }
    }

    demo地址: https://github.com/rayshen/SwiftAnimationTest

  • 相关阅读:
    sharepoint user field
    esata 安装 xp
    webservice without iis
    userdata
    png transparency
    使用命令行生成签名文件并用其对apk文件进行签名
    如何通过备份 Windows 7 “ 两个激活文件”实现重装操作系统后的自行激活
    SQLserver2008打不开的问题
    在mvc3中的@{}问题,mvc3做的有点小bug
    布局new分配 ,
  • 原文地址:https://www.cnblogs.com/rayshen/p/4906414.html
Copyright © 2011-2022 走看看