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

  • 相关阅读:
    chrome 插件备份
    github下载单个文件
    idea插件备份
    外卖类应用的竞争与趋势
    使用终端和Java API对hbase进行增删改查操作
    分布式文件系统的布局、文件查找
    Java上机实验报告(4)
    Java上机实验报告(3)
    Java上机实验报告(2)
    Java上机实验报告(1)
  • 原文地址:https://www.cnblogs.com/rayshen/p/4906414.html
Copyright © 2011-2022 走看看